开发者

How to check if an image is within a particular subview

开发者 https://www.devze.com 2023-02-24 03:26 出处:网络
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'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

精彩评论

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