美文网首页
隐式动画&显式动画 学习笔记

隐式动画&显式动画 学习笔记

作者: 嗯哎嘶唠咯 | 来源:发表于2018-01-21 18:06 被阅读141次

隐式动画


  • CALayer的属性基本上都可以进行隐式动画

  • CATransaction可以控制隐式动画(执行时间或者关闭隐式动画)

  • UIView将它关联的图层的这个特性关闭而没有动画

  • 两个重要的方法:


- (instancetype)presentationLayer

- (instancetype)modelLayer

显式动画


属性动画

CAAnimation 实现了KVC协议,可以通过 -setValue:forKey:-valueForKey:方法存取属性。但是CAAnimation如同NSDictionary可以随意设置键值,so,在有多重动画需要在代理方法中做区分的时候,会显得格外方便:


...

CABasicAnimation *animation = [CABasicAnimation animation];

[self updateHandsAnimated:NO];

animation.keyPath = @"transform";

animation.toValue = [NSValue valueWithCATransform3D:transform];

animation.duration = 0.5;

animation.delegate = self;

[animation setValue:handView forKey:@"handView"];

[handView.layer addAnimation:animation forKey:nil];

...

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

{

 //set final position for hand view

 UIView *handView = [anim valueForKey:@"handView"];

 handView.layer.transform = [anim.toValue CATransform3DValue];

}

关键帧动画

CAKeyframeAnimation 因为有个path属性,so~可以配合贝塞尔曲线实现一些复杂的动画。

虚拟属性

CALayer没有显式提供角度或者方向之类的属性,为了旋转图层,我们可以对transform.rotation关键路径应用动画,而不是transform本身。


- (void)viewDidLoad

{

 [super viewDidLoad];

 //add the ship

 CALayer *shipLayer = [CALayer layer];

 shipLayer.frame = CGRectMake(0, 0, 128, 128);

 shipLayer.position = CGPointMake(150, 150);

 shipLayer.contents = (__bridge id)[UIImage imageNamed: @"Ship.png"].CGImage;

 [self.containerView.layer addSublayer:shipLayer];

 //animate the ship rotation

 CABasicAnimation *animation = [CABasicAnimation animation];

 animation.keyPath = @"transform.rotation";

 animation.duration = 2.0;

 animation.byValue = @(M_PI * 2);

 [shipLayer addAnimation:animation forKey:nil];

}

动画组

CABasicAnimationCAKeyframeAnimation仅仅作用于单独的属性,而CAAnimationGroup可以把这些动画组合在一起

过度

CATransition

CATransition是另一个CAAnimation的子类,和别的子类不同,CATransition有一个typesubtype来标识变换效果。


- (IBAction)switchImage

{

 //set up crossfade transition

 CATransition *transition = [CATransition animation];

 transition.type = kCATransitionFade;

 //apply transition to imageview backing layer

 [self.imageView.layer addAnimation:transition forKey:nil];

 //cycle to next image

 UIImage *currentImage = self.imageView.image;

 NSUInteger index = [self.images indexOfObject:currentImage];

 index = (index + 1) % [self.images count];

 self.imageView.image = self.images[index];

}

ps:做转场动画时,可能会经常使用。

动画过程中取消动画


- (void)removeAnimationForKey:(NSString *)key;

- (void)removeAllAnimations;

小结

basicAnimationkeyAnimation 均作用与单一属性(毕竟都是propertyAnimation的子类),animationGroup 可以多个动画组合。

过渡不同于属性动画,适用场景:视图移除添加和控制器转场。

参考链接

相关文章

  • 隐式动画&显式动画 学习笔记

    隐式动画 CALayer的属性基本上都可以进行隐式动画 CATransaction可以控制隐式动画(执行时间或者关...

  • SwiftUI -- View 动画

    SwiftUI 中的动画有两种类型:显式动画和隐式动画。 一、显式动画 显式动画通过 withAnimation ...

  • iOS-CALayer (四)

    上一篇 : iOS-CALayer (三) 前言:继续深入学习动画,主要从隐式动画、显式动画上车。 一、隐式动画 ...

  • iOS隐式动画与显式动画的区别

    请参考iOS隐式动画与显式动画的区别

  • iOS动画-CAAnimation使用详解

    理解了隐式动画后,显式动画就更加通俗易懂了。区别于隐式动画的特点,显式动画就是需要我们明确指定类型、时间等参数来实...

  • iOS中显式和隐式动画的区别

    收集到的显式和隐式动画的区别: 1、隐式动画一直存在 如需关闭需设置;显式动画是不存在,如需显式 要开启(创建)。...

  • ios 动画-CoreAnimation geekband

    本次简单说3中动画, 隐式动画CATransaction,显式动画CABasicAnimation and CAK...

  • iOS面试题-每日十道-第四天

    一. 简述iOS动画机制 iOS分为显式动画,隐式动画 显式动画: 对一些属性做指定的自定义动画,或者创建非线性动...

  • iOS动画笔记

    在iOS各类动画效果中,习惯分为两类:隐式动画和显式动画。 隐式动画 简单的讲,由系统进行相关动画配置,执行动画效...

  • iOS核心动画高级技巧 - 4

    8. 显式动画 显式动画 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念。隐式动...

网友评论

      本文标题:隐式动画&显式动画 学习笔记

      本文链接:https://www.haomeiwen.com/subject/cxugoxtx.html