我正在使用 - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
移动图像。如何在移动图像后固定它的位置。我的意思是我会就像当我选择正确的位置时,图像应该不再移动。
最佳答案
将 PanGesture 添加到包含图像的 imageView。
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
[imageView addGestureRecognizer:panRecognizer];
//method to move imageView whereever you want in the view,you can also write conditions to restrict the imageView not to go beyond bounds.
- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer
{
CGPoint translation = [panRecognizer translationInView:self.view];
CGPoint imageViewPosition = imageView.center;
imageViewPosition.x += translation.x;
imageViewPosition.y += translation.y;
imageView.center = imageViewPosition;
[panRecognizer setTranslation:CGPointZero inView:self.view];
//you can use if(panRecognizer.state==UIGestureRecognizerStateEnded){} condition to fix the position of the imageView.
}
关于ios - 移动图像后如何固定图像的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19948322/