如何获取子视图在其父视图坐标系中的有效边界

发布于 2025-01-08 18:23:41 字数 340 浏览 4 评论 0原文

在我的应用程序中,我允许用户通过添加箭头(自定义 ArrowView)来注释照片。可以添加许多箭头,具有各种缩放和缩放功能。旋转。

我正在尝试通过触摸实现箭头选择。目前,我正在迭代&用于

CGRectContainsPoint(arrowView.frame, touchPoint)

根据触摸手势决定选择哪个箭头。

但是,当某些箭头很大且较小时,这效果不佳。旋转到 45 度(因为框架变大)。

问题: 我想使用转换为父坐标而不是框架的箭头边界。缩放时如何得到这个?是否应用了旋转?

或者,有没有更好的方法来解决这个选择问题?

In my app, I allow the user to annotate a photo by adding arrows (custom ArrowView). There can be many arrows added, with various zoom & rotation.

I am trying implement selecting of arrow by touch. Currently, I am iterating & using

CGRectContainsPoint(arrowView.frame, touchPoint)

to decide which arrow to select based on a touch gesture.

But, this does not work well when some of the arrows are big & rotated to 45 degrees (since the frame becomes big).

Question:
I would like to use bounds of the arrow translated to parent co-ordinates instead of frame. How can I get this when scaling & rotation is applied?

Alternatively, is there a better method to solve this selection problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找我们的幸福 2025-01-15 18:23:41

此代码找到 touchPoint 下的箭头:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self.view];
    UIView *arrow = [self.view hitTest:touchPoint withEvent:event];
}

This code find the arrow under touchPoint:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self.view];
    UIView *arrow = [self.view hitTest:touchPoint withEvent:event];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文