如何在iPhone App中抢到最高级别的Superview?
我希望能够获取应用程序的主 UIView。到目前为止,我一直在调用 [[[self.view superview] superview] superview] 来向上遍历链(或向下,取决于你如何看待它)。问题是我可能无法绝对确定我需要升多少级。有没有办法:
- 直接进入 iPhone 应用程序中的最高级别 UIView?
或者,如果不是,
- 检查当前超级视图是否是应用程序中最高级别的 UIView?
I want to be able to grab the main UIView for the application. So far, I have been calling [[[self.view superview] superview] superview] to traverse up the chain (or down, depending on how you look at it). The problem with this is that it is possible that I can't be absolutely sure the number of levels up I need to go. Is there a way to:
- Go directly to the highest level UIView in an iPhone application?
or, if not,
- Check to see if the current superview is the highest level UIView in the app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是否是您首先要寻找的,但它可以提供帮助。
如果您试图找到顶部视图以添加子视图(例如弹出窗口或其他视图),您可以使用 UIWindow,它在某种程度上是顶级视图:
I'm not sure that it's what your are looking for in the first place, but it can help.
If you are trying to find the top view in order to add a subview, like say a popup or other, you can use UIWindow, which is in some way, the top level view:
只是将其从顶部拉下来,例如检查当前视图的 superview 属性是否为空?如果是的话,我想我们可以假设它是根视图。
Just pulling this off the top, something like checking if the superview property of the current view is null? If it is I guess we may presume that it is the root view.