ios 動畫效果CATransition筆記

來源:互聯網
上載者:User

標籤:

   初學ios開發,很多概念還不清楚,所以只有邊學邊做例子。又怕學了後面忘了前面,因此用自己的部落格來紀錄自己的學習曆程,也是對自己學習不要懈怠做個監督。

    剛學ios做動畫效果。因為ios封裝得很好,實現ios的漂亮動畫效果也很簡單,卻因為我自己的粗心落了一個字母 導致糾結了一天,這個教訓必須記住,同時也懂得了調試技能在編程裡地位也是非常重要的存在。

   實現ios動畫有兩種方法:一種UIView層面的,一種是使用CATransition.

[objc] view plaincopy
  1. - (void)viewDidLoad  
  2. {  
  3.     [super viewDidLoad];  
  4.     // Do any additional setup after loading the view.  
  5.       
  6.     UIView *redView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  7.     redView.backgroundColor = [UIColor redColor];  
  8.     [self.view addSubview:redView];  
  9.       
  10.     UIView *yellowView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  11.     yellowView.backgroundColor = [UIColor yellowColor];  
  12.     [self.view addSubview:yellowView];  
  13.       
  14.     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
  15.     [button setTitle:@"改變1" forState:UIControlStateNormal];  
  16.     button.frame = CGRectMake(10, 10, 300, 40);  
  17.     [button addTarget:self action:@selector(changeUIView1) forControlEvents:UIControlEventTouchUpInside];  
  18.     [self.view addSubview:button];  
  19.       
  20.   
  21.       
  22.     UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
  23.     [button2 setTitle:@"改變2" forState:UIControlStateNormal];  
  24.     button2.frame = CGRectMake(10, 120, 300, 40);  
  25.     [button2 addTarget:self action:@selector(changeUIView2) forControlEvents:UIControlEventTouchUpInside];  
  26.     [self.view addSubview:button2];  
  27. }  
  28. -(void) changeUIView1{  
  29.     [UIView beginAnimations:@"animation" context:nil];  
  30.     [UIView setAnimationDuration:1.0f];  
  31.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  32.     [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];  
  33.     [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0  ];  
  34.     [UIView commitAnimations];  
  35. }  
  36.   
  37. -(void) changeUIView2{  
  38.    CATransition *transition = [CATransition animation];  
  39.     transition.delegate = self;  
  40.     transition.duration = 2.0f;  
  41.     transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];  
  42.     transition.type = kCATransitionPush;  
  43.     transition.type = @"pageCurl"  ;//另一種設定動畫效果方法  
  44.     transition.subtype = kCATransitionFromBottom;  
  45.     [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];  
  46.     [self.view.layer addAnimation:transition forKey:@"animation"];  
  47. }  


調用CATransition需要在frameworks中添加QuartzCore.framework,在.h檔案中加入  #import <QuartzCore/QuartzCore.h>

setType:有四種類型:

    

    kCATransitionFade                   //交叉淡化過渡

    kCATransitionMoveIn               //移動覆蓋原圖

    kCATransitionPush                    //新視圖將舊視圖推出去

    kCATransitionReveal                //底部顯出來

另一種設定方法

   pageCurl     //向上翻一頁

    pageUnCurl   //向下翻一頁

    rippleEffect   //滴水效果

    suckEffect     //收縮效果,如一塊布被抽走

    cube       //立方體效果

    oglFlip      //上下翻轉效果

 


setSubtype:有四種類型:

    

    kCATransitionFromRight;

    kCATransitionFromLeft(預設值)

    kCATransitionFromTop;

    kCATransitionFromBottom

ios 動畫效果CATransition筆記

聯繫我們

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