实现点击按钮旋转动画

 

@interface ViewController ()
{
    UIButton *button;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"arrows"] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 60, 60);
    button.center = self.view.center;
    [self.view addSubview:button];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)click:(id)sender {
    
    if (button.isSelected) {
        
        button.selected = NO;
        [UIView animateWithDuration:0.3 animations:^{
            
            button.transform = CGAffineTransformMakeRotation(0);
        }];
    } else {
        
        button.selected = YES;
        [UIView animateWithDuration:0.3 animations:^{
            
            button.transform = CGAffineTransformMakeRotation(M_PI_2);
        }];
    }
    
}

就可以实现图一图二的效果。

图一:

图二:

 

posted @ 2018-04-12 17:45  chihbun  阅读(762)  评论(0编辑  收藏  举报