ipad - UIPinchGestureRecognizer position the pinched view between the two fingers -


i implemented pinch zoom of view. however, view doesn't position wished be. stackoverflowers ipad, view centered on ipad photos.app : when pinch&zoom on album, photos present in view expanding. view approximately centered top right hand corner on first finger , bottom left hand finger on other finger. mixed pan recognizer, way user has pinch, , pan adjust.

here graphic explanation, post video of app if that's unclear (no secret, i'm trying reproduce photos.app of ipad...)

so initial position of fingers, begining zooming :

enter image description here

this actual "zoomed" frame now. square bigger, position below fingers

given start position

here have : same size, different origin.x , y :

enter image description here

(sorry poor photoshop skills ^^)

you can cgpoint of midpoint between 2 fingers via following code in method handlingpinchgesture.

cgpoint point = [sender locationinview:self]; 

my whole handlepinchgesture method below.

/* instance variables  cgfloat lastscale; cgpoint lastpoint; */  - (void)handlepinchgesture:(uipinchgesturerecognizer *)sender {     if ([sender numberoftouches] < 2)         return;      if (sender.state == uigesturerecognizerstatebegan) {         lastscale = 1.0;         lastpoint = [sender locationinview:self];     }      // scale     cgfloat scale = 1.0 - (lastscale - sender.scale);     [self.layer setaffinetransform:         cgaffinetransformscale([self.layer affinetransform],                                 scale,                                 scale)];     lastscale = sender.scale;      // translate     cgpoint point = [sender locationinview:self];     [self.layer setaffinetransform:         cgaffinetransformtranslate([self.layer affinetransform],                                     point.x - lastpoint.x,                                     point.y - lastpoint.y)];     lastpoint = [sender locationinview:self]; } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -