[IOS]图片的旋转和缩放

发布时间:2020-06-27 03:19:29 作者:蓬莱仙羽
来源:网络 阅读:511

实现图片的旋转和缩放也是IOS开发中一个比较常见的技术点,下面我们来一起学习,这功能如何实现?

效果图:

[IOS]图片的旋转和缩放  [IOS]图片的旋转和缩放
运行的时候按住alt键能够实现图片的伸缩

ViewController.h:

#import <UIKit/UIKit.h>  @interface ViewController : UIViewController <UIGestureRecognizerDelegate> {     float scale;     float prviousScale;  //放大倍数     float rotation;     float previousRotation; //旋转角度 } @property (retain, nonatomic) IBOutlet UIImageView *otherImage;  @end 

ViewController.m:

#import "ViewController.h" #import "MyGestureRecongnizer.h"  //自定义手势 @interface ViewController ()  @end  @implementation ViewController  - (void)viewDidLoad {     [super viewDidLoad];     prviousScale=1; 	     //缩放手势     UIPinchGestureRecognizer *pin=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(doPinch:)];     pin.delegate=self;     [self.otherImage addGestureRecognizer:pin];          //旋转事件     UIRotationGestureRecognizer *rotaion=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(doRotate:)];     rotaion.delegate =self;     [self.otherImage addGestureRecognizer:rotaion];               //添加自定义手势(点击到X大于200的地方相应)     MyGestureRecongnizer *my = [[MyGestureRecongnizer alloc] initWithTarget:self action:@selector(fun:)];     [self.view addGestureRecognizer:my];           } //自定义手势触发事件 -(void)fun:(MyGestureRecongnizer *)my {     NSLog(@"OK"); }  //允许同时调用两个手势,如果是no的话就只能调用一个手势 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {     return YES; }  -(void)transfromImageView {     CGAffineTransform t=CGAffineTransformMakeScale(scale*prviousScale, scale*prviousScale);     t=CGAffineTransformRotate(t, rotation+previousRotation);     self.otherImage.transform=t; }  //缩放方法 -(void)doPinch:(UIPinchGestureRecognizer *)gesture {     scale=gesture.scale; //缩放倍数     [self transfromImageView];     if (gesture.state==UIGestureRecognizerStateEnded) {         prviousScale=scale*prviousScale;         scale=1;     } }  //旋转方法 -(void)doRotate:(UIRotationGestureRecognizer *)gesture {     rotation=gesture.rotation; //旋转角度     [self transfromImageView];     if (gesture.state==UIGestureRecognizerStateEnded) {         previousRotation=rotation+previousRotation;         rotation=0;     } }   - (void)dealloc {     [_otherImage release];     [super dealloc]; } @end 



推荐阅读:
  1. Overview of WIP_PERIOD_BALANCES
  2. win7无法正常关机的解决方法【系统天地】

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

旋转和缩放

上一篇:MySQL之insert update delete 锁表情况

下一篇:智能指针类模板(五十)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》