您好,登錄后才能下訂單哦!
#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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。