开发者

How to check if an image is within a particular subview

I've got several images inside a scrollview and within my normal view. I'd like to check by means of an "if statement" if this image is inside my scrollvie开发者_如何学JAVAw or not.

i put my images inside the scroller with:

[scroller insertSubview:image belowSubview:self.view];

thanks in advance!


Have you tried:

[scroller.subviews containsObject:image];

?


If you want to add an image only if it is not added yet you can use tags. Each UIImageView should have a unique tag.

const int uniqueImageTag = 10001;
image.tag = uniqueImageTag;
if ([scroller viewWithTag:imageTag] == nil) {
    [scroller insertSubview:image belowSubview:self.view];
}


something like:

UIView *parent = [self.imageView superview];
if (parent == scroller) {
    //yep
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜