#import "ViewController.h"@interfaceViewcontroller () <UIGestureRecognizerDelegate>@property (Weak, nonatomic) Iboutlet Uiimageview*Imagev;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.self.imageV.userInteractionEnabled=YES; //Add a rotation gesture[self rotationges]; //Add a pinch gesture[self pinch]; }//simultaneous: At the same time//allow multiple gestures to be supported simultaneously-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) othergesturerecognizer{returnYES;} //Add a rotation gesture- (void) rotationges{//Add a rotation gestureUirotationgesturerecognizer *rotation =[[Uirotationgesturerecognizer alloc] initwithtarget:self action: @selector (rotationges:)]; Rotation.Delegate=Self ; [Self.imagev addgesturerecognizer:rotation];}- (void) Rotationges: (Uirotationgesturerecognizer *) rotationges{Self.imageV.transform=cgaffinetransformrotate (Self.imageV.transform, rotationges.rotation); //Reset[Rotationges setrotation:0]; } //Add a pinch gesture- (void) pinch{Uipinchgesturerecognizer*pinch =[[Uipinchgesturerecognizer alloc] initwithtarget:self action: @selector (pinch:)]; Pinch.Delegate=Self ; [Self.imagev addgesturerecognizer:pinch];}//called when zooming- (void) Pinch: (Uipinchgesturerecognizer *) pinch{NSLog (@"%s", __func__); Self.imageV.transform=Cgaffinetransformscale (Self.imageV.transform, Pinch.scale,pinch.scale); //Reset[Pinch Setscale:1];}- (void) panges{//Add a drag gestureUipangesturerecognizer *pan =[[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (pan:)]; [Self.imagev Addgesturerecognizer:pan];}//called when a view is dragged- (void) Pan: (Uipangesturerecognizer *) Pan {//gets the offset (relative to the most primitive offset)Cgpoint TRANSP =[Pan TranslationInView:self.imageV]; NSLog (@"%@", Nsstringfromcgpoint (TRANSP)); Self.imageV.transform=cgaffinetransformtranslate (Self.imageV.transform, transp.x, TRANSP.Y); //make it relative to the last time//Reset.[Pan Settranslation:cgpointzero InView:self.imageV]; }@end
Gesture recognition two for iOS development gesture processing