iOS UIImageView 分层问题

发布于 2024-10-19 15:57:47 字数 395 浏览 5 评论 0原文

我确信这个问题已经在很多地方得到了回答,但我不知道要搜索什么关键字来回答这个问题。如果有人可以将我链接到答案,那就太好了。

我不确定如何控制哪些 UIImageViews(它们都被子视图到同一视图)在视觉上覆盖其他视图。换句话说,如果我将一个 UIImageView 子视图到与另一个 UIImageView 相同的位置,则添加的第二个 UIImageView 始终覆盖第一个 UIImageView。我不确定如何在 UI 编辑器或代码中执行此操作。到目前为止,我一直按照我希望它们出现的顺序添加它们,但我不能总是这样做。特别是如果我需要将 UIImageView 设置为 IBOutlet,并且我需要它位于我以编程方式添加的所有 UIImageView 之上。

有人可以告诉我如何以编程方式执行此操作以及如何在 UI 编辑器中设置值吗?谢谢。

I am sure this question has been answered in numerous places but I have no idea what keyword to search for to answer this question. If anyone can link me to the answer that'd be great.

I'm not sure how to control which UIImageViews (which are all subviewed to the same view) cover the others visually. In other words, if I subview a UIImageView to the same location as another UIImageView, the 2nd one that was added is always covering the first one. I'm not sure how to do this either in the UI editor or in code. So far I've been adding them in the order I want them to show up but I can't always do that. Especially if I need to set UIImageView that's an IBOutlet and I need it to be on top of all the UIImageViews that I add programmatically.

Can someone show me how to do this programmatically and possibly how to set values in the UI editor? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把人绕傻吧 2024-10-26 15:57:47

UIView 有几个 API 来处理这些问题:

  • 添加子视图时:
    • 插入子视图:上面子视图:
    • 插入子视图:atIndex:
    • 插入子视图:下面子视图:
  • 按 z 顺序移动子视图:
    • 将SubviewToFront:
    • 发送SubviewToBack:
    • exchangeSubviewAtIndex:withSubviewAtIndex:

有关所有这些的更多详细信息可以在 UIView 文档(UIImageView 是其子类。)

UIView has several APIs to deal with these issues:

  • When adding a subview:
    • insertSubview:aboveSubview:
    • insertSubview:atIndex:
    • insertSubview:belowSubview:
  • Moving subviews around in their z-ordering:
    • bringSubviewToFront:
    • sendSubviewToBack:
    • exchangeSubviewAtIndex:withSubviewAtIndex:

More details on all of these can be found in the UIView documentation (of which UIImageView is a subclass.)

各自安好 2024-10-26 15:57:47

这是在 UIView 层 并且不特定于 UIImageViews。

可以使用以下 UIView 方法以编程方式“重新分层”视图:

– addSubview:
– bringSubviewToFront:
– sendSubviewToBack:
– removeFromSuperview
– insertSubview:atIndex:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– exchangeSubviewAtIndex:withSubviewAtIndex:

要在 Interface Builder 中对 XIB 执行此操作,请重新排序此视图上列出的视图,底行是最前面的对象:

xib 视图

This is done at the UIView layer and is not specific to UIImageViews.

Views can be programmatically 'relayered' with the following UIView methods:

– addSubview:
– bringSubviewToFront:
– sendSubviewToBack:
– removeFromSuperview
– insertSubview:atIndex:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– exchangeSubviewAtIndex:withSubviewAtIndex:

To do it to the XIB in Interface Builder, reorder the views listed on this view, bottom row is the frontmost object:

xib view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文