码迷,mamicode.com
首页 > 移动开发 > 详细

iOS CoreAnimation(核心动画二)

时间:2015-09-09 21:18:33      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

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];
    
}

 

iOS CoreAnimation(核心动画二)

标签:

原文地址:http://www.cnblogs.com/wangbinbin/p/4795879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!