码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 特定图片的按钮的旋转动画

时间:2014-07-25 11:22:41      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   strong   io   2014   

最近做的东西中,要为一个有特定图片的按钮添加旋转动画,Demo代码如下:

#import "ViewController.h"

@interface ViewController () {
    BOOL flag;
}

@property (strong, nonatomic) UIImageView *imageView;

@end

@implementation ViewController
            
- (void)viewDidLoad {
    [super viewDidLoad];
    
    flag = YES;
    
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
    UIImage *aImage = [UIImage imageNamed:@"down.png"];
    [_imageView setImage:aImage];
    _imageView.center = self.view.center;
    [self.view addSubview:_imageView];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"旋转" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(rotate:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(110, 400, 100, 44);
    [self.view addSubview:button];
}

- (void)rotate:(id)sender {
    if (flag) {
        [UIView animateWithDuration:0.5 animations:^{
            _imageView.transform = CGAffineTransformMakeRotation(M_PI);
        } completion:^(BOOL finished) {
            flag = NO;
        }];
    }
    else {
        [UIView animateWithDuration:0.5 animations:^{
            _imageView.transform = CGAffineTransformMakeRotation(0);
        } completion:^(BOOL finished) {
            flag = YES;
        }];
    }
}

@end

运行时真机设备和模拟器的按钮旋转动画中,方向可能有点不同,有点奇怪。

其中一些运行截图如下:

bubuko.com,布布扣

bubuko.com,布布扣

Demo地址:点击打开链接



iOS 特定图片的按钮的旋转动画,布布扣,bubuko.com

iOS 特定图片的按钮的旋转动画

标签:style   blog   http   color   os   strong   io   2014   

原文地址:http://blog.csdn.net/jymn_chen/article/details/38098499

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