Say I am having ten view controllers in my IOS application. Suppose specific events (eg: BLE connectivity success/failure) will be getting intimated in application controller.
I want to block the current view controller (whichever view controller it may be) and show a view with semi transparency for 2 seconds based on the event from application controller.
How can I achieve this in IOS. Any help may be highly appreciated.

- 5,621
- 2
- 25
- 59
3 Answers
Just set your view alpha property like
viewController.view.alpha = 0.5;

- 3,985
- 2
- 17
- 41
-
Shall I push view controller from application controller? or should I check which ever the view controller is present, I should add this view on top of that? – Sreehari Mar 31 '15 at 12:35
-
Just present view as Model View! – Retro Mar 31 '15 at 12:38
My solution for the above problem is this:
Create a custom transparent overlay UIView that comes over any view, navigationbar and tabbbar.
-In the navigation controller (or tabbar controller) that your view controller is embedded in I create a custom view with it's frame equal to the frame of the navigation controller's view.
-Then I set it offscreen by setting it's origin.y to navigationController.view.height
-Then I create 2 functions -(void)showOverlay
and -(void)hideOverlay
that animate the overlay view on and off screen:
- (void)hideOverlay{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
CGRect frm = self.helpView.frame;//helpView is my overlay
frm.origin.y = self.offscreenOffset; //this is an Y offscreen usually self.view.height
self.helpView.frame = frm;
[UIView commitAnimations];
}
- (void)showOverlay{
[self.view bringSubviewToFront:self.helpView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
CGRect frm = self.helpView.frame;
frm.origin.y = self.onscreenOffset;
self.helpView.frame = frm;
[UIView commitAnimations];
}
-In my view controller I can just call
[(MyCustomNavCtrl *)self.navigationController showOverlay];
[(MyCustomNavCtrl *)self.navigationController hideOverlay];
And that's about it.

- 1,312
- 8
- 19

- 531
- 4
- 10
setting your alpha level of a view will make all the subviews transparent as well. if you just want your background to be semi transparent do the following.
myView.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.5)
(Swift Syntax)

- 332
- 1
- 2
- 9