1

我有 2 个我希望能够移动的图像视图。这是我的代码:

panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRecognizerMethod:)];

imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
imageview.frame = CGRectMake(390, 100, 80, 16);
imageview.userInteractionEnabled = YES;
[imageview addGestureRecognizer:panRecognizer];
[self addSubview:imageview];

imageview2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
imageview2.frame = CGRectMake(390, 120, 80, 17);
imageview2.userInteractionEnabled = YES;
[imageview2 addGestureRecognizer:panRecognizer];
[self imageview2];

在我的gestureRecognizer方法中:

- (void)gestureRecognizerMethod:(UIPanGestureRecognizer *)recognizer
{
    if (recognizer.view == imageview)
    {
        if (recognizer.state == UIGestureRecognizerStateBegan || recognizer.state ==  UIGestureRecognizerStateChanged)
        {
            CGPoint startPoint = [recognizer locationInView:self];
            imageview.center = startPoint;
        }
    }
    if (recognizer.view == imageview2)
    {
        if (recognizer.state == UIGestureRecognizerStateBegan || recognizer.state == UIGestureRecognizerStateChanged)
        {
            CGPoint startPoint = [recognizer locationInView:self];
            imageview2.center = startPoint;
        }
    }
}

我只能移动其中一个视图。怎么了?

4

2 回答 2

3

Create a new gesture recognizer for the second image view. You can use the same target and action for both recognisers but you can only attach any one recogniser to a single view.

于 2013-04-27T09:49:31.083 回答
-1

Try this:

ResizeImage on github

于 2013-04-27T09:49:46.647 回答