我目前有一个可以在视图中移动/拖动的UIImageView。
当图像移动并阻止图像移出屏幕视图时,on如何检测屏幕边缘?
发布于 2011-03-13 16:58:46
您可以使用以下命令在(最外层)视图的坐标中查找UIImageView
的矩形
CGRect r = [iv convertRect:iv.bounds toView:self.view];
然后是检查r
是否越界的问题,例如:
CGRect i = CGRectIntersect(r,self.view.bounds);
if ( CGRectIsNull(i) )
{
NSLog(@"way out of bounds");
} else if ( !CGRectEqualToRect(i,r) ) {
NSLog(@"partly out of bounds");
} else {
NSLog(@"self.view envelopes imageview");
}
当然,这应该放在你的拖拽代码中,用适当的处理替换NSLog()
语句(例如,在最后一种情况下只更新位置,或者如果需要的话,通过将矩形转换回视图)
https://stackoverflow.com/questions/5290783
复制相似问题