iOS 核心動畫 Core Animation

來源:互聯網
上載者:User

標籤:

相關資料:

這個理論比較多:http://www.360doc.com/content/15/0727/09/20918780_487655250.shtml

這個實踐比較多,常見的效果都有了http://www.cnblogs.com/wengzilin/p/4250957.html

例子:放大效果。思路是讓CALayer動,CABasicAnimation是怎麼動,然後將動畫加到CALayer

    //演員初始化    CALayer *scaleLayer = [[CALayer alloc] init];    scaleLayer.backgroundColor = [UIColor blueColor].CGColor;    scaleLayer.frame = CGRectMake(100, 100, 50, 50);    scaleLayer.cornerRadius = 10;    [self.view.layer addSublayer:scaleLayer];         //設定劇本    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];    scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];    scaleAnimation.toValue = [NSNumber numberWithFloat:1.5];    scaleAnimation.autoreverses = YES;    scaleAnimation.fillMode = kCAFillModeForwards;    scaleAnimation.repeatCount = MAXFLOAT;    scaleAnimation.duration = 0.8;        //開演    [scaleLayer addAnimation:scaleAnimation forKey:@"scaleAnimation"];

 

思考:這邊要建立一個CALayer,但是如果我想讓介面上某個UIView動起來(可能是一個按鈕、圖片,等)

其實所有的視圖都繼承UIView,每個UIView都有CALayer的屬性(見第一個參考資料的描述)

所以,我們可以直接將動畫加在view的layer上。這樣代碼就變得更易懂了。

下面是個視圖旋轉的例子,麼麼噠

    UIView *v = [[UIView alloc]initWithFrame:CGRectMake(200, 100, 50, 50)];    v.backgroundColor = [UIColor redColor];    [self.view addSubview:v];    CABasicAnimation *an2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];    an2.fromValue = 0;    an2.toValue = [NSNumber numberWithFloat:M_PI*2];    an2.repeatCount = MAXFLOAT;    an2.duration = 0.8;    [v.layer addAnimation:an2 forKey:@"caan"];

 

iOS 核心動畫 Core Animation

聯繫我們

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