码迷,mamicode.com
首页 > 其他好文 > 详细

图片的抖动

时间:2016-02-15 21:22:06      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:

Main.storyboard

技术分享

ViewControlller.m

//

//  ViewController.m

//  8A03.图片的抖动

//

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

//  Copyright © 2016 huanxi. All rights reserved.

//

 

#import "ViewController.h"

 

@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

结果

技术分享

图片的抖动

标签:

原文地址:http://www.cnblogs.com/Lu2015-10-03/p/5191328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!