IOS 动画总结

来源:互联网 发布:winzip mac 5 注册码 编辑:程序博客网 时间:2024/05/19 14:01
UIView动画
使用iphone作为开发平台,你可以体验到UIView带来的既另类又有趣的动画功能,这个功能可以在更新视图时放缓节奏,产生流畅的动画效果,进而改善用户体验。
可以产生动画效果的变化包括:
1)、frame 基于父视图的位置和大小
2)、bounds 改变视图的框架和边界
3)、center  改变视图的中心
4)、transform 旋转,即仿射变换
5)、alpha  改变透明度
6)、backgroundColor 改变背景颜色
7)、contentStretch 拉伸变化

UIView动画是成块运行的。

[UIView beginAnimations:nil context:nil];//请求动画的开始

   [UIView setAnimationDuration:2];//动画时长

   if (self.seg.selectedSegmentIndex==0) {

      //动画的过渡,下翻页

[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.imgView3 cache:YES];

   }else{

      //动画的过渡,上翻页

[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.imgView3 cache:YES];

    }

   [UIView commitAnimations];//动画结束



Core Animation Transitions
CATransition只针对图层,不针对视图。图层是Core Animation与每个UIView产生联系的工作层面。使用CoreAnimation时,应该将CATransition应用到视图的默认图层上,而不是视图本身。

[CATransaction begin];//动画开始

CABasicAnimation *animation = [CABasicAnimation

                             animationWithKeyPath:@"transform" ];

   animation.fromValue =[NSValue valueWithCATransform3D:CATransform3DIdentity];

    

   //围绕Z轴旋转,垂直与屏幕

   animation.toValue= [ NSValue valueWithCATransform3D:

                     

                     

                     CATransform3DMakeRotation(M_PI, 0, 0,1.0) ];

    animation.duration = 1;

   //旋转效果累计,先转180度,接着再旋转180度,从而实现360旋转

    animation.cumulative = YES;

    animation.repeatCount = 2;

    [imgView3.layer addAnimation:animation forKey:nil];

 

[CATransaction commit];//动画结束



块语法动画

  //块方法实现移动

    UIImageView *birdView=[[UIImageView alloc]initWithFrame:CGRectMake(30, 80,45, 36)];

    birdView.center=CGPointMake(30, 80);

    birdView.image=[UIImage imageNamed:@"icon"];

    [self.view addSubview:birdView];

   //块方法,代码块,可以嵌套方法

   [UIViewanimateWithDuration:2animations:^{

       birdView.center=CGPointMake(180, 80);//横向移动小鸟

    } completion:^(BOOL finished) {

       [UIView animateWithDuration:2animations:^{

          birdView.center=CGPointMake(180, 180);//移动结束后下移

       } completion:^(BOOL finished) {

          [UIView animateWithDuration:2animations:^{

              birdView.center=CGPointMake(30, 180);

           }completion:^(BOOL finished) {

             [UIViewanimateWithDuration:2animations:^{

                 birdView.center=CGPointMake(30, 80);

              } completion:^(BOOL finished) {

                 [selfmoveBtn:nil];

                 [birdView removeFromSuperview];//移除

              }];

           }];

       }];

    }];



//下一个例子

GAffineTransform tf;

   if(self.seg.selectedSegmentIndex==0){

      tf=CGAffineTransformMakeTranslation(20,20);//相对于初始位置移动

    }else{

      tf=CGAffineTransformTranslate(self.imgView3.transform, 20,20);//相对与当前位置反复移动

    }

   [UIViewanimateWithDuration:2animations:^{

       self.imgView3.transform=tf;

    } completion:^(BOOL finished) {

       

    }];



以上这三种动画是自己用过的,这里总结一下权当复习,当然总结的不全,感觉有帮助的可以看看。





0 0
原创粉丝点击