zoukankan      html  css  js  c++  java
  • iOS 特定图片的button的旋转动画

    近期做的东西中,要为一个有特定图片的button加入旋转动画,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

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

    当中一些执行截图例如以下:


    Demo地址:点击打开链接



  • 相关阅读:
    maven 执行mvn package/clean命令出错
    IDEA
    贝叶斯
    python基础之python基本数据类型
    python基础(一)python数据类型,条件,循环
    ...
    读取70开头的xml,gbk转成utf-8
    CSS实现多个Div等高,类似表格布局
    JBOSS 5 session时间配置
    padding
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6999463.html
Copyright © 2011-2022 走看看