2011-05-04 54 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

相關問題