圖片的抖動

Main.storyboard動畫

ViewControlller.matom

//spa

//  ViewController.m3d

//  8A03.圖片的抖動orm

//blog

//  Created by huan on 16/2/4.圖片

//  Copyright © 2016 huanxi. All rights reserved.rem

//animation

 

#import "ViewController.h"it

 

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}

 

-(IBAction)start{

    //抖動圖片 使用幀動畫 設置 旋轉的 路徑

    CAKeyframeAnimation *rotationAni = [CAKeyframeAnimation animation];

    rotationAni.keyPath = @"transform.rotation";

    //計算好旋轉的弧度

    CGFloat angle = M_PI_4 * 0.3;

    //設置 旋轉的路徑 (狀態)

    

    rotationAni.values = @[@(-angle),@(angle), @(-angle)];

    //設置動畫執行的次數

    rotationAni.repeatCount = MAXFLOAT;

    [self.imageView.layer addAnimation:rotationAni forKey:@"shake"];

    

}

 

-(IBAction)stop{

    //經過key把動畫移除

    [self.imageView.layer removeAnimationForKey:@"shake"];

}

@end

結果

相關文章
相關標籤/搜索