iOS7中UIView的animateKeyframesWithDuration方法講解

來源:互聯網
上載者:User

標籤:

iOS7中UIView的animateKeyframesWithDuration方法講解

在iOS7中,給UIView添加了一個方法用來直接使用主要畫面格動畫而不用藉助CoreAnimation來實現,那就是animateKeyframesWithDuration

以下是使用源碼:

////  ViewController.m////  Created by YouXianMing on 14/11/26.//  Copyright (c) 2014年 YouXianMing. All rights reserved.//#import "ViewController.h"@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    [self runAnimateKeyframes];}- (void)runAnimateKeyframes {        /**     *  relativeDuration  動畫在什麼時候開始     *  relativeStartTime 動畫所持續的時間     */        [UIView animateKeyframesWithDuration:6.f                                   delay:0.0                                 options:UIViewKeyframeAnimationOptionCalculationModeLinear                              animations:^{                                  [UIView addKeyframeWithRelativeStartTime:0.0   // 相對於6秒所開始的時間(第0秒開始動畫)                                                          relativeDuration:1/3.0 // 相對於6秒動畫的期間(動畫持續2秒)                                                                animations:^{                                                                    self.view.backgroundColor = [UIColor redColor];                                                                }];                                                                    [UIView addKeyframeWithRelativeStartTime:1/3.0 // 相對於6秒所開始的時間(第2秒開始動畫)                                                          relativeDuration:1/3.0 // 相對於6秒動畫的期間(動畫持續2秒)                                                                animations:^{                                                                    self.view.backgroundColor = [UIColor yellowColor];                                                                }];                                  [UIView addKeyframeWithRelativeStartTime:2/3.0 // 相對於6秒所開始的時間(第4秒開始動畫)                                                          relativeDuration:1/3.0 // 相對於6秒動畫的期間(動畫持續2秒)                                                                animations:^{                                                                    self.view.backgroundColor = [UIColor greenColor];                                                                }];                                                                }                              completion:^(BOOL finished) {                                  [self runAnimateKeyframes];                              }];}@end

細節之處:

 

iOS7中UIView的animateKeyframesWithDuration方法講解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.