Core Animation之转场动画

1、转场动画简单介绍

CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。iOS比Mac OS X的转场动画效果少一点
UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果
属性解析:
type:动画过渡类型
subtype:动画过渡方向
startProgress:动画起点(在整体动画的百分比)
endProgress:动画终点(在整体动画的百分比)

2、转场动画效果类型

转场动画效果.png

3、图片浏览器的转场动画效果

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
// 图片索引
@property (nonatomic,assign) int index;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.index = 1;
    
}

- (IBAction)previousImageAnimation:(UIButton *)sender {
    self.index--;
       if (self.index<1) {
              self.index=11;
           }
       self.iconView.image=[UIImage imageNamed: [NSString stringWithFormat:@"%03d.jpg",self.index]];
    
       //创建核心动画
       CATransition *caanimation=[CATransition animation];
        //告诉要执行什么动画
        //设置过度效果
       caanimation.type=@"cube";
       //设置动画的过度方向(向左)
       caanimation.subtype=kCATransitionFromLeft;
       //设置动画的时间
       caanimation.duration=2.0;
        //添加动画
      [self.iconView.layer addAnimation:caanimation forKey:nil];

}
- (IBAction)nextImageAnimation:(UIButton *)sender {
    self.index++;
    if (self.index>11) {
        self.index = 1;
    }
    self.iconView.image=[UIImage imageNamed: [NSString stringWithFormat:@"%03d.jpg",self.index]];
    
    //创建核心动画
    CATransition *caanimation=[CATransition animation];
    //告诉要执行什么动画
    //设置过度效果
    caanimation.type=@"cube";
    //设置动画的过度方向(向右)
    caanimation.subtype=kCATransitionFromRight;
    //设置动画的时间
    caanimation.duration=2.0;
    //添加动画
    [self.iconView.layer addAnimation:caanimation forKey:nil];

}

@end

执行的效果

Untitled.gif
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 文 || 張贺 Core Animation简介 Core Animation,中文翻译为核心动画,它是一组非常强...
    張贺阅读 6,208评论 9 35
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 8,413评论 1 23
  • 一、简介 Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽...
    莦婼姑娘阅读 4,558评论 0 4
  • Core Animation 核心动画 Core Animation是一组非常强大的动画处理API,使用它能做出非...
    iOS_Cqlee阅读 6,807评论 0 8
  • 核心动画的基本结构 CAAnimation 是个虚类 不能直接使用 继承之下有三个子类 CAAnimationG...
    藤王俊采阅读 3,089评论 1 2

友情链接更多精彩内容