如何检查图像是否在特定子视图中
问题描述:
我在滚动视图内和正常视图内有多个图像。如果此图像位于我的滚动视图内,我希望通过“if语句”进行检查。如何检查图像是否在特定子视图中
我把我的卷轴内的图像与:
[scroller insertSubview:image belowSubview:self.view];
在此先感谢!
答
如果您想添加图片,只有在尚未添加图片的情况下才可以使用标签。每个UIImageView
应该有一个唯一的标签。
const int uniqueImageTag = 10001;
image.tag = uniqueImageTag;
if ([scroller viewWithTag:imageTag] == nil) {
[scroller insertSubview:image belowSubview:self.view];
}
答
类似:
UIView *parent = [self.imageView superview];
if (parent == scroller) {
//yep
}
可能重复(http://stackoverflow.com/questions/4929747/how-do-i-detect-whenever-two [如何检测凡两个重叠的UIImageView?] -uiimageview-overlap) – 2011-04-13 13:04:25