ios 動畫學習(-)UIView 內建動畫

來源:互聯網
上載者:User

標籤:++   主要畫面格   mod   let   ping   hdu   set   ubi   context   

ios 開發中,一些常用的簡單的動畫可以用 uivew 內建的動畫來是實現

今天就學習下 UIVIew 一些常用的動畫

1.

 // 翻轉的動畫    [UIView beginAnimations:@"doflip" context:nil];    //設定時常    [UIView setAnimationDuration:1];    //設定動畫淡入淡出    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];    //設定代理    [UIView setAnimationDelegate:self];    //設定翻轉方向    [UIView setAnimationTransition:     UIViewAnimationTransitionFlipFromLeft  forView:self.redView cache:YES];    //動畫結束    [UIView commitAnimations];

  效果:

2. 位移動畫

 [UIView beginAnimations:@"move" context:nil];    [UIView setAnimationDuration:2];    [UIView setAnimationDelegate:self];    //改變它的frame的x,y的值    self.redView.frame=CGRectMake(100,100, 120,100);    [UIView commitAnimations];

效果:

另一種寫法:

 [UIView animateWithDuration:0.5 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{        CGPoint point = _redView.center;        point.y += 150;        [_redView setCenter:point];    } completion:^(BOOL finished) {            }];

  效果:

3.主要畫面格動畫

 void (^keyFrameBlock)() = ^(){        // 建立顏色數組        NSArray *arrayColors = @[[UIColor orangeColor],                                 [UIColor yellowColor],                                 [UIColor greenColor],                                 [UIColor blueColor],                                 [UIColor purpleColor],                                 [UIColor redColor]];        NSUInteger colorCount = [arrayColors count];        // 迴圈添加主要畫面格        for (NSUInteger i = 0; i < colorCount; i++) {            [UIView addKeyframeWithRelativeStartTime:i / (CGFloat)colorCount                                    relativeDuration:1 / (CGFloat)colorCount                                          animations:^{                                              [_redView setBackgroundColor:arrayColors[i]];                                          }];        }    };    [UIView animateKeyframesWithDuration:5.0                                   delay:0.0                                 options:UIViewKeyframeAnimationOptionCalculationModeCubic | UIViewAnimationOptionCurveLinear                              animations:keyFrameBlock                              completion:^(BOOL finished) {                                  // 動畫完成後執行                                  // code...                              }];

  效果:

ios 動畫學習(-)UIView 內建動畫

聯繫我們

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