动画

iOS Core Animation(六)- 显式动画

2016-12-22  本文已影响69人  莫须有恋
CABasicAnimation

当有多个动画时,区分动画的方式:

//添加动画是设置key
[self.view.layer addAnimation:animation forKey:@"animationKey"];
//在代理中,通过animationForKey:进行比较
[anim isEqual:[self.view.layer animationForKey:@"animationKey"]]

*CAAnimation实现了KVC协议,可以通过key-value为动画添加标识

//添加key-value
[animation setValue:@"animation" forKey:@"animationKey"];
//在代理中,进行比较
[[anim valueForKey:@"animationKey"] isEqualToString:@"animation"]
CAKeyframeAnimation - 关键帧动画

*可以设置一连串个随意的值做动画(values)

CAAnimationGroup - 动画组

一个继承于CAAnimation的子类,添加了一个animations数组的属性,用来组合其他的动画。

CATransition - 过渡
    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    [self.imageView.layer addAnimation:transition forKey:nil];
    UIImage *currentImage = self.imageView.image;
    NSUInteger index = [self.images indexOfObject:currentImage];
    index = (index + 1) % [self.images count];
    self.imageView.image = self.images[index];
 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    [self.tabBarController.view.layer addAnimation:transition forKey:nil];
}
自定义动画

+ (void)transitionWithView: duration: options:animations: completion:
+ (void)transitionFromView: toView: duration: options: completion:

动画过程中取消动画

通过-addAnimation: forKey:中的key来移除动画,-removeAnimationForKey:

简单记录

实现动画的方式

上一篇:iOS Core Animation(五)
下一篇:iOS Core Animation(七)

上一篇 下一篇

猜你喜欢

热点阅读