在我的应用程序中,我允许用户通过添加箭头(自定义 ArrowView)来注释照片。可以添加很多箭头,具有各种缩放和旋转。
我正在尝试通过触摸实现箭头选择。目前,我正在迭代和使用
CGRectContainsPoint(arrowView.frame, touchPoint)
根据触摸手势决定选择哪个箭头。
但是,当一些箭头很大并且旋转到 45 度时(因为框架变大),这就不太适用了。
问题: 我想使用转换为父坐标而不是框架的箭头边界。应用缩放和旋转时如何获得此信息?
或者,有没有更好的方法来解决这个选择问题?
最佳答案
此代码找到 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];
}
关于iphone - 如何在其父 View 的坐标系中获得 subview 的有效边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9445139/