Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So, you're only concerned with left / right panning...</p> <p>Let's assume you have 2 UIImageViews, a &amp; b, as subviews of some other UIView and defined as class members of some class.</p> <p>You can get help detecting panning gestures (dragging touches) on each of these views by creating instances of UIPanGestureRecognizer and adding them to each UIImageView using method addGestureRecognizer:</p> <p>When creating each UIPanGestureRecognizer, you need to designate a selector to receive the gesture events. Let say it's called didMove:</p> <p>Now, some sample code:</p> <pre><code>- (void) didMove:(UIPanGestureRecognizer*)recognizer { UIView* view = [recognizer view]; // Remember our UIImageViews are class members called, a &amp; b // UIView* otherView = view == a ? b : a; if (recognizer.state == UIGestureRecognizerStateBegin || recognizer.state == UIGestureRecognizerStateChanged) { // Moving left will have a negative x, moving right positive // CGPoint translation = [recognizer translationInView:view.superview]; view.center = CGPointMake(view.center.x + translation.x, view.center.y); // Reset so we always track the translation from the current view position // [recognizer setTranslation:CGPointZero inView:view.superview]; if (CGRectIntersectsRect(view.frame, otherView.frame)) { // Translate by the same number of points to keep views in sync // otherView.center = CGPointMake(otherView.center.x + translation.x, otherView.center.y); } } } </code></pre> <p>It may not be exactly what you need, but it should give you a good idea how it could be done.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload