gpt4 book ai didi

ios - 移动图像后如何固定图像的位置?

转载 作者:行者123 更新时间:2023-11-28 19:06:38 24 4
gpt4 key购买 nike

我正在使用 - (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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com