#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIGestureRecognizerDelegate> { float scale; float prviousScale; //放大倍数 float rotation; float previousRotation; //旋转角度 } @property (retain, nonatomic) IBOutlet UIImageView *otherImage; @end
#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
新闻名称:[IOS]图片的旋转和缩放
文章链接:https://www.cdcxhl.com/article10/pocjdo.html
成都网站建设公司_创新互联,为您提供企业建站、Google、品牌网站设计、静态网站、做网站、品牌网站制作
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联