Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- how to add UIPanGestureRecognizer to UIImageView
- -(void)initialization
- UIPanGestureRecognizer *panRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)] autorelease];
- [panRecognizer setMinimumNumberOfTouches:1];
- [panRecognizer setMaximumNumberOfTouches:1];
- [panRecognizer setDelegate:self];
- [imageview addGestureRecognizer:panRecognizer];
- }
- - (void)move:(UIPanGestureRecognizer *)gestureRecognizer
- {
- UIView *piece = imageview;
- [self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
- if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
- CGPoint translation = [gestureRecognizer translationInView:[piece superview]];
- CGPoint translatedCenter = CGPointMake([piece center].x + translation.x, [piece center].y + translation.y);
- CGPoint center = [self centerWithBounds:translatedCenter andViewFrame:[piece frame] andBoundingFrame:[[piece superview] frame]];
- [piece setCenter:center];
- [gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment