码迷,mamicode.com
首页 > 移动开发 > 详细

iOS -- 通过transform对图片进行移动和缩放

时间:2015-09-17 01:08:49      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"

@interface ViewController ()

 - (IBAction)move:(UIButton *)sender;

- (IBAction)zoom:(UIButton *)sender;

- (IBAction)rotate:(UIButton *)sender;

 @end

@implementation ViewController

// 移动

- (IBAction)move:(UIButton *)sender {

    UIButton *img = (UIButton *)[self.view viewWithTag:10];

    switch (sender.tag){

        case 1: // 上

            img.transform = CGAffineTransformTranslate(img.transform, 0, -10);

            break;

        case 2: // 下

            img.transform = CGAffineTransformTranslate(img.transform, 0, 10);

            break;

        case 3: // 左

            img.transform = CGAffineTransformTranslate(img.transform, -10, 0);

            break;

        case 4: // 右

            img.transform = CGAffineTransformTranslate(img.transform, 10, 0);

            break;

    }

}

// 缩放

- (IBAction)zoom:(UIButton *)sender {

    UIButton *img = (UIButton *)[self.view viewWithTag:10];

    switch (sender.tag){

        case 5: // 放大

            img.transform = CGAffineTransformScale(img.transform, 1.2, 1.2);

            break;

        case 6: // 缩小

            img.transform = CGAffineTransformScale(img.transform, 0.8, 0.8);

            break;

    }

}

#pragma mark 旋转

- (IBAction)rotate:(UIButton *)sender {

    UIButton *img = (UIButton *)[self.view viewWithTag:10];

    switch (sender.tag){

        case 7: // 左旋转

            img.transform = CGAffineTransformRotate(img.transform, -0.25);

            break;

        case 8: // 右旋转

            img.transform = CGAffineTransformRotate(img.transform, 0.25);

            break;

    }

}

@end

iOS -- 通过transform对图片进行移动和缩放

标签:

原文地址:http://www.cnblogs.com/lianfu/p/4814908.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!