ios - scale, rotate and move with UIGestureRecognizer simultaneously -


i can't find out why scale, rotate , move won't work @ same time..

i have looked @ lot of examples , can't seem find problem. firstly thought gesturerecognizer shouldrecognizesimultaneouslywithgesturerecognizer problem, wasn't please :)

here code:

@implementation storyeditorpageholderview    - (bool)gesturerecognizer:(uigesturerecognizer *)gesturerecognizer shouldrecognizesimultaneouslywithgesturerecognizer:(uigesturerecognizer *)othergesturerecognizer{     return yes; } - (id)initwithproperty:(property *)property scale:(cgfloat)scalefactor pos:(cgpoint)point dustbin:(dustbinview *)dustbin{     self = [super initwithframe:cgrectzero];     if(self){         self.imageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:property.imagename]];           self.frame = cgrectmake(0, 0, self.imageview.frame.size.width, self.imageview.frame.size.height);         [self addsubview:_imageview];          uipinchgesturerecognizer *pinchrecognizer = [[uipinchgesturerecognizer alloc] initwithtarget:self action:@selector(scale:)];         [self addgesturerecognizer:pinchrecognizer];          uirotationgesturerecognizer *rotationrecognizer = [[uirotationgesturerecognizer alloc] initwithtarget:self action:@selector(rotate:)];         [self addgesturerecognizer:rotationrecognizer];          uipangesturerecognizer *panrecognizer = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(move:)];         [panrecognizer setminimumnumberoftouches:1];         [panrecognizer setmaximumnumberoftouches:1];         [self addgesturerecognizer:panrecognizer];          uitapgesturerecognizer *tapprofileimagerecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tapped:)];         [tapprofileimagerecognizer setnumberoftapsrequired:2];         [self addgesturerecognizer:tapprofileimagerecognizer];        }     return self; }  - (void)rotate:(uirotationgesturerecognizer *)rotate {     if (rotate.state == uigesturerecognizerstatebegan) {         prevrotation = 0.0;     }      float thisrotate = rotate.rotation - prevrotation;     prevrotation = rotate.rotation;     self.transform = cgaffinetransformrotate(self.transform, thisrotate); }  - (void)scale:(uipinchgesturerecognizer *)pinch {     if (pinch.state == uigesturerecognizerstatebegan)         prevpinchscale = 1.0;      float thisscale = 1 + (pinch.scale-prevpinchscale);     prevpinchscale = pinch.scale;     self.transform = cgaffinetransformscale(self.transform, thisscale, thisscale); }  -(void)move:(uipangesturerecognizer *)pan {      if (pan.state == uigesturerecognizerstatebegan){         prevpanpoint = [pan locationinview:self.superview];     }      cgpoint curr = [pan locationinview:self.superview];      float diffx = curr.x - prevpanpoint.x;     float diffy = curr.y - prevpanpoint.y;      cgpoint centre = self.center;     centre.x += diffx;     centre.y += diffy;     self.center = centre;      prevpanpoint = curr; } @end 

i have uigesturerecognizerdelegate delegate in .h file:

#import <foundation/foundation.h>   @class property; @class dustbinview;  @interface storyeditorpropertyview : uiview <uigesturerecognizerdelegate>  @property (strong, nonatomic) uipangesturerecognizer *panrecognizer; @property (strong, nonatomic) uipinchgesturerecognizer *pinchrecognizer; @property (strong, nonatomic) uirotationgesturerecognizer *rotationrecognizer; @property (strong, nonatomic) uitapgesturerecognizer *tapprofileimagerecognizer; @property (strong, nonatomic) uiimageview *imageview; @property (strong, nonatomic) property *property; @property (nonatomic) cgpoint pointbegin; @property (nonatomic) bool isremoveable; @property (nonatomic) cgfloat beginscale; @property (strong, nonatomic) dustbinview *dustbin;  - (id)initwithproperty:(property *)property scale:(cgfloat)scalefactor pos:(cgpoint)point dustbin:(dustbinview *)dustbin;  @end 

this worked me:

uipinchgesturerecognizer *pinchrecognizer = [[uipinchgesturerecognizer alloc] initwithtarget:self action:@selector(scale:)]; pinchrecognizer.delegate = self; [self addgesturerecognizer:pinchrecognizer];  uirotationgesturerecognizer *rotationrecognizer = [[uirotationgesturerecognizer alloc] initwithtarget:self action:@selector(rotate:)]; pinchrecognizer.delegate = self; [self addgesturerecognizer:rotationrecognizer];  uipangesturerecognizer *panrecognizer = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(move:)]; pinchrecognizer.delegate = self; [panrecognizer setminimumnumberoftouches:1]; [panrecognizer setmaximumnumberoftouches:1]; [self addgesturerecognizer:panrecognizer]; 

Comments

Popular posts from this blog

javascript - JS causing window size to be bigger than necessary - Dropdown bug -

php - Calling a template part from a post -

How to mention the localhost in android -