加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 如何测试一个点是否在视图中

发布时间:2020-12-15 01:56:44 所属栏目:百科 来源:网络整理
导读:我有一个UIImageView,我有一个CGPoint在屏幕上。我想能够测试这一点,看看它是否在UIImageView中。这样做最好的方法是什么?请帮忙? 解决方法 参考点CGPoint是不错的。如果你的观点在窗口坐标中,那么可以使用它 CGPoint locationInView = [imageView conv
我有一个UIImageView,我有一个CGPoint在屏幕上。我想能够测试这一点,看看它是否在UIImageView中。这样做最好的方法是什么?请帮忙?

解决方法

参考点CGPoint是不错的。如果你的观点在窗口坐标中,那么可以使用它

CGPoint locationInView = [imageView convertPoint:point fromView:imageView.window];
if ( CGRectContainsPoint(imageView.bounds,locationInView) ) {
    // Point lies inside the bounds.
}

您也可以拨打pointInside:withEvent:方法

if ( [imageView pointInside:locationInView withEvent:nil] ) {
    // Point lies inside the bounds
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读