设为首页 加入收藏

TOP

核心动画中的动画组和转场动画(一)
2014-11-23 21:34:22 来源: 作者: 【 】 浏览:6
Tags:核心 动画
所谓的动画组就是将一些动画组合起来给layer使其的动画更丰富灵活。
它很简单,就是为其animations属性赋值一个动画数组。
 
- (void)demoAnimationGroup  
{  
    static NSString * const kCAPostionKeyPath = @"position";  
    static NSString * const kCAOpacityKeyPath = @"opacity";  
    static NSString * const kCARotationKeyPath = @"transform.rotation";  
    static NSString * const kCAScaleKeyPath = @"transform.scale";  
      
    UIBezierPath *path = [UIBezierPath bezierPath];  
    [path moveToPoint:_demoView.layer.position];  
    [path addCurveToPoint:CGPointMake(260, 400) controlPoint1:CGPointMake(0, 460) controlPoint2:CGPointMake(320, 0)];  
      
    //路径动画  
    CAKeyframeAnimation *posAnimation = [CAKeyframeAnimation animationWithKeyPath:kCAPostionKeyPath];  
    posAnimation.path = path.CGPath;  
    posAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];  
      
    //透明度动画  
    CABasicAnimation *opaAnimation = [CABasicAnimation animationWithKeyPath:kCAOpacityKeyPath];  
    opaAnimation.duration = 2.0f;  
    opaAnimation.toValue = @(0.3f);  
    opaAnimation.autoreverses = YES;  
      
    //旋转动画  
    CABasicAnimation *rotAnimation = [CABasicAnimation animationWithKeyPath:kCARotationKeyPath];  
    rotAnimation.duration = 2.0f;  
    rotAnimation.toValue = @(M_PI);  
    rotAnimation.autoreverses = YES;  
      
    //缩放动画  
    CABasicAnimation *scaAnmaiton = [CABasicAnimation animationWithKeyPath:kCAScaleKeyPath];  
    scaAnmaiton.duration = 2.0f;  
    scaAnmaiton.toValue = @(1.5f);  
    scaAnmaiton.autoreverses = YES;  
      
    //设置动画组  
    CAAnimationGroup *group = [CAAnimationGroup animation];  
    group.animations = @[posAnimation, opaAnimation, rotAnimation, scaAnmaiton];  
    group.duration = 4.0f;  
    group.removedOnCompletion = NO;  
    group.fillMode = kCAFillModeForwards;  
      
    [_demoView.layer addAnimation:group forKey:nil];  
}  

这个动画组对demoView的layer加入了一些同时进行的动画,比如双控制点的贝塞尔路径,透明度的渐隐渐明,旋转以及缩放等。
CATransition
转场动画几乎在所有的APP上都能遇见,经常用于视图控制器的切换或者单视图控制器的页面切换等,也可以在自定义UIStoryboardSegue中来加入动画效果。
它也是CAAnimation的子类,能为图层提供移出屏幕和移入的动画效果。
其常用属性为
type 过渡类型
subtype 过渡类型的子类型,方向设置
其中过渡类型有很多,最初有四个版本,后来又加入了一些,以字符串形式设置。
最初的四个:fade,push,moveIn,reveal
以后加入的效果则更加丰富和炫目,有 cube, oglFlip, suckEffect, rippleEffect, pageCurl, pageUnCurl, cameraIrisHollowOpen, cameraIrisHollowClose。
- (void)viewTransition  
{  
    static NSString * const kCATransitionTypeFlip = @"oglFlip";     //翻页效果  
      
    CATransition *transition = [CATransition animation];  
    transition.type = kCATransitionTypeFlip;  
    transition.subtype = kCATransitionFromRight;  
    transition.duration = 1.5f;  
    [_transitionOrangeView.layer addAnimation:transition forKey:nil];  
      
    [self.view performSelector:@selector(sendSubviewToBack:) withObject:_transitionOrangeView afterDelay:1.0f];  
}  

这个方法简单的实现了view翻页的效果,当然目前控制器的根view只有一个subview,所以使用sendSubviewToBack的方法后显示的还是这个view,但是看到了动画效果。
现在UIView的转场动画有了更方便的类方法
+ transitionWithView:duration:options:animations:completion:
+ transitonFromView:toView:duration:options:completion:
这两个方法参数加入了苹果推荐的块代码,也让转场动画都在一个方法中进行处理,也对动画结束进行了处理,更加方便易用。
- (void)anotherTransition  
{  
    _transitionBlueView = [[UIView alloc] initWithFrame:self.view.bounds];  
    _transitionBlueView.backgroundColor = [UIColor blueColor];  
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 2874 (LCA) 下一篇hdu 2871 Memory Control 伸展树..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)
·使用华为开发者空间 (2025-12-27 04:19:24)
·Getting Started wit (2025-12-27 03:49:24)
·Ubuntu 上最好用的中 (2025-12-27 03:49:20)