你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS動畫-定時對UIView進行翻轉和抖動的方法

iOS動畫-定時對UIView進行翻轉和抖動的方法

編輯:IOS開發綜合

(翻轉)方式一:

[NSTimer scheduledTimerWithTimeInterval:3.f repeats:YES block:^(NSTimer * _Nonnull timer) {
      CABasicAnimation* rotationAnimation = [CABasicAnimation animation];;
      rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
      rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
      rotationAnimation.duration = 1;
      // 切換界面保證動畫不停止
      rotationAnimation.removedOnCompletion = NO;
      rotationAnimation.repeatCount = 1;
      [self.bindCardImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    }];

(翻轉)方式二(這種方式較好一些):

CABasicAnimation *waitAnimation = [CABasicAnimation animation];
    waitAnimation.toValue = [NSNumber numberWithFloat:1.0];
    waitAnimation.duration = 3.f;
    waitAnimation.beginTime = 3.f;

    CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 1.f;

    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.duration = 4.f;
    group.repeatCount = CGFLOAT_MAX;
    group.removedOnCompletion = NO;

    [group setAnimations:@[waitAnimation, rotationAnimation]];

    [self.bindCardImageView.layer addAnimation:group forKey:@"bindCardImageViewAnimation"];

抖動:

CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  //設置抖動幅度
  shake.fromValue = [NSNumber numberWithFloat:-0.2];
  shake.toValue = [NSNumber numberWithFloat:+0.2];
  shake.duration = 0.1;
  shake.autoreverses = YES; //是否重復
  shake.repeatCount = 3;

  [itemView.iconImageView.layer addAnimation:shake forKey:@"imageView"];

以上這篇iOS動畫-定時對UIView進行翻轉和抖動的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持本站。

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved