ios - iOS 中的接触点坐标未正确映射

标签 ios objective-c

我正在尝试创建一个允许用户在图像上移动框架的应用程序,以便我可以在选定区域应用一些效果。

我需要允许用户精确地拖动和缩放图像上的蒙版框。我需要它是准确的,就像任何其他照片应用程序一样。

我的策略是在触摸移动事件上获取用户的触摸点,并相应地缩放我的框架。这是非常直观的。我编写了以下代码来处理触摸移动事件:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:[self view]];


    float currX = touchPoint.x;
    float currY = touchPoint.y;

    /*proceed with other operations on currX and currY, 
      which is coming out quite well*/

}

但唯一的问题是,currXcurrY 变量的坐标并不完全是它们应该在的位置。有一个视差错误,它不断地从一个设备转移到另一个设备。我还认为在 iPad 的情况下 x 和 y 坐标会被交换。

你能帮我弄清楚如何获得准确的触摸坐标吗?

我的背景图像在一个 View 中 (imageBG),而 mask 框架在一个单独的 View 中 (maskBG)。我试过了:

CGPoint touchPoint = [touch locationInView:[maskBG view]];

CGPoint touchPoint = [touch locationInView:[imageBG view]];

...但同样的问题仍然存在。我还注意到触摸错误在 iPad 上比在 iPhone 或 iPod 上更严重。

最佳答案

image.center = [[[event allTouches] anyObject] locationInView:self.view];

关于ios - iOS 中的接触点坐标未正确映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15060902/

相关文章:

ios - 为什么我不能为某些特定的 iOS 模拟器构建?

ios - 识别 UIScrollView 中的滑动手势

ios - Xcode 9 "could not build module ‘Foundation’“

iphone - Objective C iPhone 性能问题

objective-c - 自定义 UIButtons 的有效方法

ios - 根据车辆路线获取从一个地点到另一地点的路线

iOS将 subview 添加到 ScrollView

iphone - 何时正确释放对象

objective-c - 谷歌应用样式帮助查看

ios - AFNetworking 2.0 - 如何异步下载 uiimage