有谁知道我将如何在 Xcode 中检查与 UIImageView 的触摸接近度?我正在尝试检查触摸是否在围绕屏幕移动的 UIImageView 的 25 像素内。任何帮助,将不胜感激。谢谢你。
问问题
158 次
1 回答
0
首先,您可以接触到:
UITouch *touch = [[event allTouches] anyObject];
接下来,您要检查相对于图像视图的 locationInView。
CGPoint touchlocation = [touch locationInView:self]; // or possibly myimage instead of self.
接下来,CGRectContainsPoint 返回一个布尔值。它应该是:
if ( CGRectContainsPoint( imgView.frame, touchlocation ) ) {
// inside imgView
} else {
// outside imgView Now we will found out is it within proximityImgViewRect
CGRect *proximityImgViewRect = CGRectMake( imgView.frame.origin.x-25,imgView.frame.origin.y - 25, imgView.frame.size.width+50,imgView.frame.size.height+50);
if ( CGRectContainsPoint( proximityImgViewRect.frame, touchlocation ) ) {
// inside proximityImgViewRect
} else {
//outside proximityImgViewRect
}
}
于 2012-09-17T05:38:05.327 回答