我正在尝试为 UIImageView 实现 UIPanGestureRecognizer。目前,我能够拖动 UIImageView 并限制我将其移动到的位置并且可以工作。但是,它正在移动似乎是 UIImageView 的副本,并且原始 UIImageView 保留在原地。为什么会出现这种情况?
创建 UIImageView 并将其添加到主视图后,我将添加手势识别器:
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(tileDragged:)];
pan.maximumNumberOfTouches = 1;
pan.minimumNumberOfTouches = 1;
[tileImageView addGestureRecognizer:pan];
然后在我的 tileDragged 方法中:
case UIGestureRecognizerStateChanged:
{
PuzzleTileView *tileView = (PuzzleTileView *)[self.allTiles objectAtIndex:panGesture.view.tag];
CGFloat x = 0.0;
CGFloat y = 0.0;
// x and y are calculated.
[tileView setTransform:CGAffineTransformMakeTranslation(x, y)];
break;
}