[英]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]];
}
}
I add the gesture to the imageview its not calling move action. 我将手势添加到imageview的不调用移动动作中。
how to add the gesture to only UIImageView .. 如何将手势添加到仅UIImageView ..
Try setting imageview.userInteractionEnabled = YES
. 尝试设置
imageview.userInteractionEnabled = YES
。 UIImageViews has userInteractionEnabled
set to NO
by default. UIImageViews默认将
userInteractionEnabled
设置为NO
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.