【问题标题】:Animate UIView above all other views动画 UIView 高于所有其他视图
【发布时间】:2013-06-26 17:33:40
【问题描述】:

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

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

什么是好的选择?

【问题讨论】:

  • 创建一个单例 UIView 并将该实例放在每个 viewController 上可能是一种选择?

标签: ios animation uiview


【解决方案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];

看看有没有帮助:)

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多