CATransform3D 层的几何转换(贝塞尔曲线)

demo:

ChangeDemo.zip (112.8 KB)



关键代码:

- (void)changeCurrentSubView {

        

   animationIsStop =NO;

    [CATransactionbegin];

    [CATransactionsetCompletionBlock:^(void){animationIsStop =YES;}];

    [CATransactionsetValue:[NSNumbernumberWithFloat:1.0]forKey:kCATransactionAnimationDuration];

    

   CABasicAnimation *shrinkAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.scale"];

    shrinkAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];

    shrinkAnimation.toValue = [NSNumbernumberWithFloat:0];

    shrinkAnimation.fillMode=kCAFillModeForwards;

    shrinkAnimation.removedOnCompletion=NO;

    [[[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer]addAnimation:shrinkAnimationforKey:@""];

    

    

   CABasicAnimation *fadeAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];

    fadeAnimation.toValue = [NSNumbernumberWithFloat:0];

    fadeAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];

    fadeAnimation.fillMode=kCAFillModeForwards;

    fadeAnimation.removedOnCompletion=NO;

    [[[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer]addAnimation:fadeAnimationforKey:@""];

    

    

   CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];

    CGMutablePathRef positionPath = CGPathCreateMutable();

   CGPathMoveToPoint(positionPath,NULL, [[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer].position.x

                      [[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer].position.y);

    

   CGPathAddQuadCurveToPoint(positionPath,NULL

                              -[[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer].position.x

                              [[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer].position.y

                              [[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer].position.x

                              [[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer].position.y);

    

    positionAnimation.path = positionPath;

    positionAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];

    [[[imagesViewArrayobjectAtIndex:CurrentImageNumber]layer]addAnimation:positionAnimationforKey:@"positionAnimation"];

    

   if (CurrentImageNumber >=imagesCount -1) {

        

       CurrentImageNumber = -1;

    }

    

   CABasicAnimation *shrinkAnimation2 = [CABasicAnimationanimationWithKeyPath:@"transform.scale"];

    shrinkAnimation2.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];

    shrinkAnimation2.fromValue = [NSNumbernumberWithFloat:0.001];

    shrinkAnimation2.toValue = [NSNumbernumberWithFloat:1.0];

    shrinkAnimation2.fillMode=kCAFillModeForwards;

    shrinkAnimation2.removedOnCompletion=NO;

    [[[imagesViewArrayobjectAtIndex:CurrentImageNumber +1]layer]addAnimation:shrinkAnimation2forKey:@""];

    

    

   CABasicAnimation *fadeAnimation2 = [CABasicAnimationanimationWithKeyPath:@"opacity"];

    fadeAnimation2.toValue = [NSNumbernumberWithFloat:1.0];

    fadeAnimation2.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];

    fadeAnimation2.fillMode=kCAFillModeForwards;

    fadeAnimation2.removedOnCompletion=NO;

    [[[imagesViewArrayobjectAtIndex:CurrentImageNumber +1] layer]addAnimation:fadeAnimation2forKey:@""];

    

    

   CAKeyframeAnimation *positionAnimation2 = [CAKeyframeAnimationanimationWithKeyPath:@"position"];

    positionAnimation2.delegate =self;

    CGMutablePathRef positionPath2 = CGPathCreateMutable();

    CGPathMoveToPoint(positionPath2, NULL, [[imagesViewArrayobjectAtIndex:CurrentImageNumber +1]layer].position.x

                      [[imagesViewArrayobjectAtIndex:CurrentImageNumber +1]layer].position.y);

    

    CGPathAddQuadCurveToPoint(positionPath2, NULL, [[imagesViewArrayobjectAtIndex:CurrentImageNumber +1]layer].position.x +self.frame.size.width

                              [[imagesViewArrayobjectAtIndex:CurrentImageNumber +1]layer].position.y

                              [[imagesViewArrayobjectAtIndex:CurrentImageNumber +1]layer].position.x

                              [[imagesViewArrayobjectAtIndex:CurrentImageNumber +1]layer].position.y);

    

    positionAnimation2.path = positionPath2;

    positionAnimation2.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];

    [[[imagesViewArrayobjectAtIndex:CurrentImageNumber +1]layer]addAnimation:positionAnimation2forKey:@"positionAnimation"];

    

    [CATransactioncommit];

   CurrentImageNumber++;

}













  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值