iOS開發日記55-隱式與顯式動畫

今天博主有一個隱式與顯式動畫的需求,遇到了一些困難點,在此和你們分享,但願可以共同進步.php

iOS開發中的動畫分爲兩種:一種爲UIView動畫,又稱隱式動畫,動畫後frame的數值發生了變化.另外一種是CALayer動畫,又稱顯示動畫,動畫後模型層的數據不會發生變化,圖形回到原來的位置.可是在實際開發中,由於UIView能夠相應用戶交互,因此UIView動畫用的多.動畫

一.UIview的動畫ui

1.實現方式:動畫塊,blockorm

begin開發

//設置動畫效果  修改屬性值,動畫時長等等animation

conmmitit

2.屬性動畫,過渡動畫io

①屬性動畫支持6種:transform 結構體 6個form

②過渡動畫:容器視圖,兩個子視圖容器

二.CALayer動畫  ==   核心動畫   ==   CAAnimation動畫

CAAnimation  抽象類

animation

①.CAAnimationGroup  組合動畫

②.CATransition  過渡動畫

③.CAPropertyAnimation  屬性動畫(layer的屬性)

animationWithKeyPath

CABasicAnimation  基本動畫

fromValue toValue

CAKeyFrameAnimation  關鍵幀動畫

values

下面貼出UIView動畫的代碼,與你們分享,CALayer動畫,也就是Core Animation各位看官能夠自行百度.

1.

    //使用動畫塊設置動畫

    

    //開始設置動畫 第一個參數:動畫的名字 第二個參數:能夠用來傳值

    [UIView beginAnimations:@"哈哈" context:nil];

    

    //設置動畫的時長

    [UIView setAnimationDuration:1.5];

    [UIView setAnimationRepeatAutoreverses:YES];

    

    //根據需求設置視圖的屬性變化

    _showView.backgroundColor=[UIColor grayColor];

    _showView.center=CGPointMake(200, 200);

    

    //提交動畫設置,開始執行動畫

    [UIView commitAnimations];

 2.

    //使用Block設置動畫

    

    [UIView animateWithDuration:1.5 animations:^{

        

        //動畫效果設置

        _showView.backgroundColor=[UIColor yellowColor];

        //延時

        [UIView setAnimationDelay:1.0];

 

        //能夠經過設置transform實現視圖移動

          

    } completion:^(BOOL finished) {

        

        //動畫完成後的設置

        NSLog(@"動畫完成");

    }];

 

http://www.cocoachina.com/cms/wap.php?plg_nld=1&action=article&id=7597&plg_auth=1&plg_uin=1&plg_dev=1&plg_nld=1&plg_usr=1&plg_vkey=1

相關文章
相關標籤/搜索