gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:44:49 26 4
gpt4 key购买 nike

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

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

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

-(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/

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