2011-11-16 98 views
0
-(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]]; 
     } 
    } 

我将手势添加到imageview中,而不是调用移动操作。如何将UIPanGestureRecognizer添加到UIImageView中

如何手势加起来也只有UIImageView的..

回答

16

尝试设置imageview.userInteractionEnabled = YES。 UIImageViews默认情况下将userInteractionEnabled设置为NO

+0

其工作很好谢谢hellozimi – kiran

相关问题