美文网首页IOSios
浅析UIView动画之transform

浅析UIView动画之transform

作者: Z了个L | 来源:发表于2016-12-21 11:29 被阅读315次

transform的简单使用

程序一开始显示图片:

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageV;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

// 上移
- (IBAction)moveUp:(id)sender {
    //平移
    [UIView animateWithDuration:0.5 animations:^{
        // 使用Make,它是相对于最原始的位置做的形变,开发中,不用这个,只能移动一次,
        // 看见有Make,就只能移动一次,
        // self.imageV.transform = CGAffineTransformMakeTranslation(0, -50);
        // 相对于上一次做形变,开发中经常使用下面的
        self.imageV.transform = CGAffineTransformTranslate(self.imageV.transform, 0, -50);
    }];

}

// 下移
- (IBAction)moveDown:(id)sender {

    //平移
    [UIView animateWithDuration:0.5 animations:^{
        //使用Make,它是相对于最原始的位置做的形变.
        //self.imageV.transform = CGAffineTransformMakeTranslation(0, 50);
        //相对于上一次做形变.
        self.imageV.transform = CGAffineTransformTranslate(self.imageV.transform, 0, 50);
    }];
}

// 旋转
- (IBAction)rotation:(id)sender {

    [UIView animateWithDuration:0.5 animations:^{

        //旋转(旋转的度数, 是一个弧度)
        //self.imageV.transform = CGAffineTransformMakeRotation(M_PI_4);

        self.imageV.transform = CGAffineTransformRotate(self.imageV.transform, M_PI_4);

    }];

}

// 缩放
- (IBAction)scale:(id)sender {


    [UIView animateWithDuration:0.5 animations:^{

        //缩放
        //self.imageV.transform = CGAffineTransformMakeScale(0.5, 0.5);
        self.imageV.transform = CGAffineTransformScale(self.imageV.transform, 0.8, 0.8);

    }];


}

@end

上移效果图片:


下移效果图片:


旋转效果图片:


缩放效果图片:


相关文章

网友评论

    本文标题:浅析UIView动画之transform

    本文链接:https://www.haomeiwen.com/subject/zukqvttx.html