view旋转动画

来源:互联网 发布:淘宝网平板电脑的架子 编辑:程序博客网 时间:2024/06/08 11:53
#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


0 0
原创粉丝点击