标签:
CATransition :转场动画 翻转动画
@interface ViewController () - (IBAction)previous:(UIButton *)sender; - (IBAction)next:(UIButton *)sender; @property (strong, nonatomic) IBOutlet UIImageView *iconView; @property(nonatomic,assign)int index;//当前图片的索引 @property (strong, nonatomic) IBOutlet UIView *myView; @end
//下一页
- (IBAction)next:(UIButton *)sender { self.index++; if (self.index==9) { self.index=0; } NSString * filename=[NSString stringWithFormat:@"%d.jpg",self.index+1]; self.iconView.image=[UIImage imageNamed:filename]; //转场动画 CATransition * anim=[CATransition animation]; //翻转的类型 anim.type=@"pageCurl"; //翻转方向 // anim.subtype=kCATransitionFromRight; //从多少进度开始翻 anim.startProgress=0.3; //到多少进度结束 anim.endProgress=0.5; [self.iconView.layer addAnimation:anim forKey:nil]; }
上一页
- (IBAction)previous:(UIButton *)sender { self.index--; if (self.index==-1) { self.index=8; } NSString * filename=[NSString stringWithFormat:@"%d.jpg",self.index+1]; self.iconView.image=[UIImage imageNamed:filename]; //转场动画 CATransition * anim=[CATransition animation]; //翻转的类型 anim.type=@"pageUnCurl"; //翻转方向 // anim.subtype=kCATransitionFromLeft; [self.iconView.layer addAnimation:anim forKey:nil]; }
CAAnimationGroup:组合动画
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //创建旋转动画对象 CABasicAnimation * rotate =[CABasicAnimation animation]; rotate.keyPath=@"transform.rotation"; rotate.toValue=@(M_PI); //创建缩放动画对象 CABasicAnimation * scale=[CABasicAnimation animation]; scale.keyPath=@"transform.scale"; scale.toValue=@(0.0); //添加动画 CAAnimationGroup * group =[CAAnimationGroup animation]; group.duration=2.0; group.removedOnCompletion=NO; group.fillMode=kCAFillModeForwards; group.repeatCount=MAX_CANON; group.animations=@[scale]; group.animations=@[rotate,scale]; [self.myView.layer addAnimation:group forKey:nil]; }
标签:
原文地址:http://www.cnblogs.com/wangbinbin/p/4795879.html