Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay a view over whole screen, when using UITabBarController?

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?

like image 301
cannyboy Avatar asked Oct 04 '10 17:10

cannyboy


4 Answers

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.

like image 58
Chase Roberts Avatar answered Nov 03 '22 10:11

Chase Roberts


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.

like image 26
Septronic Avatar answered Sep 18 '22 05:09

Septronic


You could attach your new view to your window directly.

[[[UIApplication sharedApplication] keyWindow] addSubview:myNewView];
like image 27
Henrik P. Hessel Avatar answered Nov 03 '22 09:11

Henrik P. Hessel


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.

like image 13
Bhavin Avatar answered Nov 03 '22 09:11

Bhavin