将UIView设置为高于所有其他视图

时间:2013-06-26 17:33:41

标签: ios animation uiview

我想在我的应用的整个内容上方显示/动画UIView。以下方法有效,但将所有内容附加到窗口并不是一个好主意。

[[[[UIApplication sharedApplication] delegate] window] addSubview:view]

什么是好的选择?

2 个答案:

答案 0 :(得分:1)

我认为您可以尝试使用visibleViewController方法来获取顶级viewController

//Try this to get the top viewController
UIViewController *vc =  [app.rootViewController visibleViewController];

// After getting the top viewController, and then add your subview to it
[vc addSubView:view];
// and try bringing this view to the top
[vc bringSubViewTo....(fogot~):view];

看看它是否有帮助:)

答案 1 :(得分:0)

我认为这种方法是正确的,你需要将它附加到窗口,因为你可能不知道视图层次结构是什么。

您可以做些什么来整理代码,将该逻辑封装到可通过AppDelegate或其他方式访问的某些方法中:

- (void)addAlwaysVisibleView:(UIView *)topmostView;
- (void)removeAlwaysVisibleView;

然后AppDelegate可以保持状态,并知道是否已经附加了“始终可见”视图,以便在需要时保持秩序并进行一些大扫除。

相关问题