Guest User

Untitled

a guest
Aug 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. Push a UIImageView with another UIImageView, possible?
  2. - (void) didMove:(UIPanGestureRecognizer*)recognizer {
  3. UIView* view = [recognizer view];
  4.  
  5. // Remember our UIImageViews are class members called, a & b
  6. //
  7. UIView* otherView = view == a ? b : a;
  8.  
  9. if (recognizer.state == UIGestureRecognizerStateBegin
  10. || recognizer.state == UIGestureRecognizerStateChanged) {
  11.  
  12. // Moving left will have a negative x, moving right positive
  13. //
  14. CGPoint translation = [recognizer translationInView:view.superview];
  15. view.center = CGPointMake(view.center.x + translation.x, view.center.y);
  16.  
  17. // Reset so we always track the translation from the current view position
  18. //
  19. [recognizer setTranslation:CGPointZero inView:view.superview];
  20.  
  21. if (CGRectIntersectsRect(view.frame, otherView.frame)) {
  22. // Translate by the same number of points to keep views in sync
  23. //
  24. otherView.center = CGPointMake(otherView.center.x + translation.x, otherView.center.y);
  25. }
  26. }
  27. }
Add Comment
Please, Sign In to add comment