2011-05-04 57 views
0

我在我的应用程序中实现了旋转,匹克,轻拍手势识别器。我有一个图像视图,我获取用户图像,然后有按钮移动到邮票视图,其中有120个可滚动的邮票图像1000 * 。问题是,当我选择一个邮票图像时,手势工作正常。但是当我再次移动到邮票视图并选择邮票时,第一个邮票变为静态,并且不识别任何手势,只有当前邮戳识别手势。 我正在执行的是选择多个邮票,然后我可以旋转他们,拉伸他们,捏他们。 这里是一个我很implementing.Just帮助我如何达致这代码...如何在相同的图像视图上实现不同的GestureRecognizer?

-(void)viewWillAppear:(BOOL)animated 
{ 
if (stampImageView) { 
     [stampImageView release]; 
    } 
    stampImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.view.center.x-100, 200, 80, 80)]; 
    stampImageView.tag=(int)mAppDel.frameImageString; 
    NSLog(@"tag is %@",stampImageView.tag); 
    stampImageView.userInteractionEnabled=YES; 
    if(mAppDel.frameImageString) 
    stampImageView.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:mAppDel.frameImageString ofType:@"png"]]; 
    [self.view addSubview:stampImageView]; 
    stampImageView.userInteractionEnabled=YES; 
       [self.view bringSubviewToFront:stampImageView]; 
       UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotatePiece:)]; 

       [stampImageView addGestureRecognizer:rotationGesture]; 
       [rotationGesture release]; 

       UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)]; 
       [pinchGesture setDelegate:self]; 
       [stampImageView addGestureRecognizer:pinchGesture]; 
       [pinchGesture release]; 

       UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panPiece:)]; 
       [panGesture setMaximumNumberOfTouches:1]; 
       [panGesture setDelegate:self]; 
       [stampImageView addGestureRecognizer:panGesture]; 
       [panGesture release]; 

} 

回答

0

难道ü尝试使用委托方法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer; 
+0

是的,我尝试过这种方法,以及返回肯定的,但什么都没有发生,而且当我移动在针对当前邮票,我可以看到以前的邮票观点是返现小号咚咚view.Just帮我兄弟在这种情况下 – Sabby 2011-05-04 07:01:59

0

我实现这个逻辑MonoTouch的,但你可以用它,在你应用程式

void AddGestureRecognizersToImage (UIImageView imgView) 
{ 
    imgView.UserInteractionEnabled = true; 

    // rotate the images 
    var rotationGesture = new UIRotationGestureRecognizer (this, new Selector ("RotateImage")); 
    imgView.AddGestureRecognizer (rotationGesture); 

    // Zoom the image 
    var pinchGesture = new UIPinchGestureRecognizer (this, new Selector ("ScaleImage")); 
    //pinchGesture.Enabled = true; 
    pinchGesture.Delegate = new GestureDelegate (this); 
    imgView.AddGestureRecognizer (pinchGesture); 

    var panGesture = new UIPanGestureRecognizer(this, new Selector ("PanImage")); 
    //panGesture.Enabled = true; 
    panGesture.MaximumNumberOfTouches = 2; 
    panGesture.Delegate = new GestureDelegate (this); 
    imgView.AddGestureRecognizer (panGesture); 

    var longPressGesture = new UILongPressGestureRecognizer (this, new Selector ("ShowResetMenu")); 
    imgView.AddGestureRecognizer (longPressGesture); 
} 

void AdjustAnchorPointForGestureRecognizer (UIGestureRecognizer gestureRecognizer) 
{ 
    if (gestureRecognizer.State == UIGestureRecognizerState.Began) 
    { 
     var image = gestureRecognizer.View; 
     var locationInView = gestureRecognizer.LocationInView (image); 
     var locationInSuperview = gestureRecognizer.LocationInView (image.Superview); 

     image.Layer.AnchorPoint = new PointF (locationInView.X/image.Bounds.Size.Width, locationInView.Y/image.Bounds.Size.Height); 
     image.Center = locationInSuperview; 
    } 
} 

[Export("RotateImage")] 
void RotateImage (UIRotationGestureRecognizer gestureRecognizer) 
{ 
    AdjustAnchorPointForGestureRecognizer (gestureRecognizer); 
    if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) 
    { 
     gestureRecognizer.View.Transform *= CGAffineTransform.MakeRotation (gestureRecognizer.Rotation); 

     // Reset the gesture recognizer's rotation - the next callback will get a delta from the current rotation. 
     gestureRecognizer.Rotation = 0; 
    } 
} 

// Zoom the image by the current scale 

[Export("ScaleImage")] 
void ScaleImage (UIPinchGestureRecognizer gestureRecognizer) 
{ 
    AdjustAnchorPointForGestureRecognizer (gestureRecognizer); 
    if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) 
    { 
     gestureRecognizer.View.Transform *= CGAffineTransform.MakeScale (gestureRecognizer.Scale, gestureRecognizer.Scale); 
     // Reset the gesture recognizer's scale - the next callback will get a delta from the current scale. 
     gestureRecognizer.Scale = 1; 
    } 
} 

// Shift the image's center by the pan amount 

[Export("PanImage")] 
void PanImage (UIPanGestureRecognizer gestureRecognizer) 
{   
    gestureRecognizer.Enabled = true; 
    AdjustAnchorPointForGestureRecognizer (gestureRecognizer); 

    var image = gestureRecognizer.View; 

    if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) 
    {   
     var translation = gestureRecognizer.TranslationInView (this.window); 
     gestureRecognizer.View.Center = new PointF (gestureRecognizer.View.Center.X + translation.X, gestureRecognizer.View.Center.Y + translation.Y); 

     //image.Center = new PointF (image.Center.X + translation.X, image.Center.Y + translation.Y); 

     // Reset the gesture recognizer's translation to {0, 0} - the next callback will get a delta from the current position. 
     gestureRecognizer.SetTranslation (PointF.Empty, image); 
    } 
} 
+0

感谢您的回答...但它被问了很久以前...干杯 – Sabby 2012-04-10 13:49:07

相关问题