Overlay a view over whole screen, when using UITabBarController?

帅比萌擦擦* 提交于 2019-12-03 06:02:21

You could attach your new view to your window directly.

[[[UIApplication sharedApplication] keyWindow] 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.

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.

Vladimir Vishnyagov

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!