#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
view旋转动画
最新推荐文章于 2023-06-25 20:51:27 发布