IOS学习动画一之UIKit动画

IOS的 普通动画可使用UIKit提供的动画方式;

专注于为中小企业提供做网站、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业周村免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

           复杂动画可使用Core Animation。

1、 通过动画上下文使用UIKit动画

-(void)animationOfUIKit  {  
    UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];  
      
    [self.view addSubview:redView];  
    //开始动画  
    [UIView beginAnimations:@"test" context:nil];  
    //动画时长  
    [UIView setAnimationDuration:1];  
    //设置动画淡入淡出  
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    /*  
     *要进行动画设置的地方  
     */  
    redView.backgroundColor=[UIColor blueColor];  
    redView.frame=CGRectMake(50, 50, 200, 200);  
    redView.alpha=0.5;
    //动画结束  
    [UIView commitAnimations];  
}

2、通过代码块使用UIKit动画

-(void)animationOfBlock  {  
    //初始化一个View,用来显示动画  
    UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
    [self.view addSubview:redView];  
  
    [UIView animateWithDuration:1 //时长  
                 delay:0 //延迟时间  
                 options:UIViewAnimationOptionTransitionFlipFromLeft//动画效果  
                 animations:^{
                         //动画设置区域  
                         redView.backgroundColor=[UIColor blueColor];  
                         redView.frame=CGRectMake(50, 50, 200, 200);  
                         redView.alpha=0.5;  
                     } completion:^(BOOL finish){  
                       //动画结束时调用  
                     }];
}

3、UIView的,翻转、旋转,偏移,翻页,缩放,取反的动画效果

CoreGraphics框架中的CGAffineTransform类可用于设定UIView的transform属性,控制视图的缩放、旋转和平移等操作 (另称为 放射变换矩阵),这种动画都是针对视图的原定最初位置的中心点为起始参照进行相应操作的,在操作结束之后可对设置量进行还原:

view.transform=CGAffineTransformIdentity;

翻转的动画

    //开始动画  
   [UIView beginAnimations:@"doflip" context:nil];  
   //设置时常  
   [UIView setAnimationDuration:1];  
   //设置动画淡入淡出  
   [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
   //设置代理  
   [UIView setAnimationDelegate:self];  
   //设置翻转方向  
   [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:manImageView cache:YES];  
   //动画结束  
   [UIView commitAnimations];

旋转动画

//创建一个CGAffineTransform  transform对象  
CGAffineTransform  transform;   
//设置旋转度数  
transform = CGAffineTransformRotate(manImageView.transform,M_PI/6.0);  
//动画开始  
[UIView beginAnimations:@"rotate" context:nil ];  
//动画时常  
[UIView setAnimationDuration:2];  
//添加代理  
[UIView setAnimationDelegate:self];  
//获取transform的值  
[manImageView setTransform:transform];  
//关闭动画  
[UIView commitAnimations];

偏移动画

[UIView beginAnimations:@"move" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
//改变它的frame的x,y的值
manImageView.frame=CGRectMake(100,100, 120,100);
[UIView commitAnimations];

翻页动画

[UIView beginAnimations:@"curlUp" context:nil];  
//指定动画曲线类型,该枚举是默认的,线性的是匀速的  
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//设置动画时常  
[UIView setAnimationDuration:1];  
[UIView setAnimationDelegate:self];  
//设置翻页的方向  
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:manImageView cache:YES];  
//关闭动画  
[UIView commitAnimations];

缩放动画

CGAffineTransform  transform = CGAffineTransformScale(manImageView.transform,1.2,1.2);  
[UIView beginAnimations:@"scale" context:nil];  
[UIView setAnimationDuration:2];  
[UIView setAnimationDelegate:self];  
[manImageView setTransform:transform];  
[UIView commitAnimations];

取反的动画效果是根据当前的动画取他的相反的动画

CGAffineTransform transform = CGAffineTransformInvert(manImageView.transform);  
[UIView beginAnimations:@"Invert" context:nil];  
[UIView setAnimationDuration:2];//动画时常  
[UIView setAnimationDelegate:self];  
[manImageView setTransform:transform];//获取改变后的view的transform  
[UIView commitAnimations];//关闭动画

文章题目:IOS学习动画一之UIKit动画
当前路径:http://bzwzjz.com/article/ipsgdd.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 宜宾网站设计 网站制作 手机网站制作设计 自适应网站建设 成都定制网站建设 成都网站建设 重庆网站建设 网站建设方案 成都网站设计 重庆手机网站建设 成都网站建设 专业网站设计 高端网站设计推广 成都网站设计 手机网站建设套餐 营销型网站建设 成都响应式网站建设公司 网站建设公司 企业网站设计 网站制作公司 成都网站制作公司 网站建设改版