关于 CABasicAnimation 实现效果

由于项目需要一个 从小变大 并且翻转的效果 所以我就花时间 研究了这么一个东西   
点击小图 翻转 并且扩充到全屏幕 高手请绕行~  

//点击图片

- ( void)selectImageView{


            CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];

            boundsAnimation.fromValue = [NSValue valueWithCGRect:self.testImageView.bounds];

            boundsAnimation.toValue = [NSValue valueWithCGRect:self.view.bounds];

            

            CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];

            positionAnimation.fromValue = [NSValue valueWithCGPoint:self.testImageView.center];

            positionAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds))];     

    

    

            CATransition *t = [CATransition animation];

            t.type = @"flip";

            t.subtype = kCATransitionFromRight;

            t.duration = 0.25;

            

            CAAnimationGroup *group = [CAAnimationGroup animation];

            group.duration = 0.5;

            group.animations = [NSArray arrayWithObjects:boundsAnimation, positionAnimation, nil];

            group.fillMode = kCAFillModeForwards;

            group.removedOnCompletion = NO;

            group.delegate = self;

            [self.testImageView.layer addAnimation:group forKey:@"zoomIn"];

            [self.testImageView.layer addAnimation:t forKey:@"flip"];

        


}


//返回初始状态 


- (void)TurnSelect{



    

    CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];

    boundsAnimation.fromValue = [NSValue valueWithCGRect:self.view.bounds];

    boundsAnimation.toValue = [NSValue valueWithCGRect:self.testImageView.bounds];

    

    CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];

    positionAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds))];     

    positionAnimation.toValue = [NSValue valueWithCGPoint:self.testImageView.center];

    

    

    CATransition *t = [CATransition animation];

    t.type = @"flip";

    t.subtype = kCATransitionFromLeft;

    t.duration = 0.25;

    t.removedOnCompletion = YES;  

    CAAnimationGroup *group = [CAAnimationGroup animation];

    

    

    group.duration = 0.5;

    group.animations = [NSArray arrayWithObjects:positionAnimation, boundsAnimation, nil];

    group.delegate = self;

    group.fillMode = kCAFillModeForwards;

    group.removedOnCompletion = NO;

    

    [self.testImageView.layer addAnimation:group forKey:@"zoomOut"];

    [self.testImageView.layer addAnimation:t forKey:@"flip"];

}


- (void)animationDidStart:(CAAnimation *)anim{

    [self.testImageView.layer removeAnimationForKey:@"flip"];


}



- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag

{

    [self.testImageView.layer removeAnimationForKey:@"flip"];

    

}



- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    self.testImageView = [[[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds ] autorelease];

    self.testImageView.image = [UIImage imageNamed:@"108.jpg"];

    self.testImageView.contentMode = UIViewContentModeScaleAspectFit;

    self.testImageView.userInteractionEnabled = YES;

    [self.view addSubview:self.testImageView];

    self.testImageView.frame = CGRectMake(300, 800, 100, 100);

//    self.testImageView.center = self.view.center;

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectImageView) ] ;

    [self.testImageView addGestureRecognizer:tapGesture];

    [tapGesture release];

 

    

    

    UIButton *testBtn = [[[UIButton alloc]initWithFrame:CGRectMake(700, 700, 100, 100) ] autorelease];

    testBtn.backgroundColor = [UIColor greenColor];

    [testBtn addTarget:self action:@selector(TurnSelect) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:testBtn];

    

}


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值