【问题标题】:How to check if an image is within a particular subview如何检查图像是否在特定子视图中
【发布时间】:2011-04-13 13:00:12
【问题描述】:

我在滚动视图和普通视图中有几张图片。我想通过“if 语句”检查此图像是否在我的滚动视图中。

我把我的图片放在滚动条中:

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

提前致谢!

【问题讨论】:

标签: iphone cocoa-touch image uiscrollview


【解决方案1】:

你试过了吗:

[scroller.subviews containsObject:image];

?

【讨论】:

  • 图像是 UIImageView,我猜 ;)
  • 感谢 Tovi7,您的回答完成了这项工作! :-D
【解决方案2】:

如果您只想添加尚未添加的图像,则可以使用标签。每个UIImageView 都应该有一个唯一的标签。

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

【讨论】:

    【解决方案3】:

    类似:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 2012-02-03
      • 2015-04-06
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多