使用 UITabBarController 时覆盖整个屏幕的视图?

发布于 2024-09-25 21:27:12 字数 120 浏览 3 评论 0原文

我想在 UITabBarController 设置中在整个屏幕上覆盖 HUD 样式的透明图形。执行此操作的按钮位于第一个选项卡的屏幕(FirstViewController)中,并且覆盖层也应该覆盖选项卡......这可能吗?

I want to overlay a HUD-style transparent graphic over the entire screen in a UITabBarController setup. The button to do this is in the first tab's screen (FirstViewController), and the overlay should also cover the tabs... is this possible?

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

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

发布评论

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

评论(5

吝吻 2024-10-02 21:27:12

您可以将新视图直接附加到窗口。

[[[UIApplication sharedApplication] keyWindow] addSubview:myNewView];

You could attach your new view to your window directly.

[[[UIApplication sharedApplication] keyWindow] addSubview:myNewView];
沩ん囻菔务 2024-10-02 21:27:12

Henrik P. Hessel 的上述解决方案很好,但该解决方案有一个问题。 elsurudo 在答案下面的评论中已经提到了这个问题。

这个解决方案的问题是出现了覆盖层
上下颠倒,不旋转。

我遇到了同样的问题,尝试了不同的方法,并找到了一个解决方案来消除该问题。

解决方案很简单。您可以将该 myNewView 添加到 UITabBarController 的视图中。

[self.tabBarController.view addSubview:myNewView];

希望它对未来的访客有用。

The above solution by Henrik P. Hessel is Good but there is one problem with that solution. The problem is already mentioned by elsurudo in the comment below the Answer.

The problem I have with this solution is that the overlay comes up
upside-down, and does not rotate.

I faced the same problem and I tried different things and I got one solution to eliminate that problem.

The solution is simple. You can add that myNewView to UITabBarController's view.

[self.tabBarController.view addSubview:myNewView];

Hope, it will be useful for future visitors.

就像说晚安 2024-10-02 21:27:12
UIView *modal = [[UIView alloc] initWithFrame:self.view.window.frame];
[self.view.window addSubview:modal];

这可能与上面提到的 [[UIApplication sharedApplication] keyWindow] 相同。但我喜欢通过当前的观点来引用它。

UIView *modal = [[UIView alloc] initWithFrame:self.view.window.frame];
[self.view.window addSubview:modal];

This might be the same as the [[UIApplication sharedApplication] keyWindow] mentioned above. But I like referencing it through the current view.

怼怹恏 2024-10-02 21:27:12

受到 rdelmar 对另一个问题的回答的启发,我建议将 UITabBarController 放在 Container View other ViewController 中。然后将你的HUD添加到ViewController视图上。

答案屏幕截图

Inspired by rdelmar's answer to another question, I recommend putting your UITabBarController in Container View other ViewController. Then add your hud onto ViewController view.

screenshot for answer

乞讨 2024-10-02 21:27:12

我真的很喜欢 Chase Robert 在这里写的内容,所以我想也提供 Swift 3. 版本:

    if let window = view.window {
        let subView = UIView(frame: window.frame)
        window.addSubview(subView)
    }

我也添加了条件,这样如果没有窗口,你就不会崩溃。

I really liked what Chase Robert had written here, so I thought to provide the Swift 3. version as well:

    if let window = view.window {
        let subView = UIView(frame: window.frame)
        window.addSubview(subView)
    }

I added the condition as well, so you don't get a crash if there's no windows.

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