Iphone 如何在相同的图像视图上实现不同的手势识别器?

Iphone 如何在相同的图像视图上实现不同的手势识别器?,iphone,uigesturerecognizer,Iphone,Uigesturerecognizer,我正在我的应用程序中实现旋转、pich、点击手势识别器。我有一个图像视图,可以在其中获取用户图像,然后有一个按钮可以移动到stamps视图,其中有120个1000*100的可滚动邮票图像。问题是,当我选择一个stampimage时,这个手势很好。但是当我再次移动到“戳记”视图并选择“戳记”时,第一个戳记将变为静态,并且不识别任何手势,只有当前戳记识别该手势。 我要做的是选择多个图章,然后旋转、拉伸、挤压它们。 这是我正在实现的代码。请帮助我如何实现它 -(void)viewWillAppear:

我正在我的应用程序中实现旋转、pich、点击手势识别器。我有一个图像视图,可以在其中获取用户图像,然后有一个按钮可以移动到stamps视图,其中有120个1000*100的可滚动邮票图像。问题是,当我选择一个stampimage时,这个手势很好。但是当我再次移动到“戳记”视图并选择“戳记”时,第一个戳记将变为静态,并且不识别任何手势,只有当前戳记识别该手势。 我要做的是选择多个图章,然后旋转、拉伸、挤压它们。 这是我正在实现的代码。请帮助我如何实现它

-(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];

}

你试过使用委托方法吗

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

我为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);
    }
}

是的,我也尝试过这个方法,返回是,但什么也没发生,而且当我将当前的邮票移到视图上时,我可以看到以前的邮票视图返回到当前的邮票视图。在这种情况下,请帮帮我兄弟谢谢你的回答…但是很久以前有人问过…干杯