ios開發核心動畫五:轉場動畫

來源:互聯網
上載者:User

標籤:

 

 

#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIImageView *imageV;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];                   }static int _i = 1;-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {            //轉場代碼與轉場動畫必須得在同一個方法當中.        //轉場代碼//    _i++;//    if (_i == 4) {//        _i = 1;//    }//    //    NSString *imageName = [NSString stringWithFormat:@"%d",_i];//    self.imageV.image = [UIImage imageNamed:imageName];////    //    //添加轉場動畫//    CATransition *anim = [CATransition animation];//    anim.duration  = 1;//    //設定轉場的類型//    anim.type = @"pageCurl";//    //    //設定動畫的起始位置//    anim.startProgress = 0.3;//    //設定動畫的結束位置//    anim.endProgress = 0.5;//    //    //    //    [self.imageV.layer addAnimation:anim forKey:nil];            //            [UIView transitionWithView:self.imageV duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:^{                //轉場 代碼        _i++;        if (_i == 4) {            _i = 1;        }                NSString *imageName = [NSString stringWithFormat:@"%d",_i];        self.imageV.image = [UIImage imageNamed:imageName];    } completion:^(BOOL finished) {            }];    }- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

 

1.什麼是轉場動畫?

就是從一個情境轉換到另一個情境,像導航控制器的push效果,就是一個轉場.

 

2.如何建立轉場動畫

  建立轉場動畫

      CATransition *anim = [CATransition animation];

      設定轉場類型

      anim.type = @"cube";

      anim.duration = 1;

      設定轉場的方向

      anim.subtype = kCATransitionFromLeft;

  設定動畫的開始位置

      anim.startProgress = 0.5;

  設定動畫的結束位置

      anim.endProgress  =0.8;

      添加動畫.了

     [_imageV.layer addAnimation:anim forKey:nil];

 

 

要執行動畫的代碼稱為轉場代碼.

轉場動畫要和轉場代碼寫在同一個方法當中才有動畫效果.

 

3.UIView進行轉場動畫

 

  [UIView transitionWithView:self.imageV duration:1 

    options:UIViewAnimationOptionTransitionFlipFromRight 

    animations:^{

        轉場代碼

        } completion:^(BOOL finished) {

        動畫執行完畢時調用.

    }];

   

    使用UIView轉場的類型比較少.

ios開發核心動畫五:轉場動畫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.