Reputation: 757
I need to add black semi transparent view below popup in such a way that it covers everything on back and is removed when popup is dismissed. Just like we do in popover for iPad Or Actionsheet.
This is the image of what i want to achieve :
If you see the transparent view is above status bar and tabbar as well.
this is the code i wrote to achieve it:
bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width ,[UIScreen mainScreen].applicationFrame.size.height)];
bgView.center = self.view.center;
bgView.backgroundColor = [UIColor blackColor];
bgView.alpha = 0.70;
-(void)showDatePicker:(InvoiceDateCell *)cell WithDatePickerView:(DatePicker *)dateView{ [self.view insertSubview:bgView belowSubview:dateView]; }
But, this doesn't covers status bar, sometimes not even nav bar.
Any pointers, how this is implemented in iOS. It is used very frequently in iOS.
Upvotes: 1
Views: 2855
Reputation: 1222
You can do it in another way, you need to create a new viewController for the pop-up, in this viewController you need to set the background colour black with alpha 0.5 and also you need to create a view in the centre of this viewController as a pop-up view.
Note: You need to set some property of this viewController as picture show below,
Now you need to present this view controller when ever you need a pop-up, and dismiss whenever you need to hide pop-up
Upvotes: 1
Reputation:
Swift 4 / Swift 5
let containerView = transitionContext.containerView
// Backdrop
dimmedView.backgroundColor = .black
dimmedView.alpha = 0.0
containerView.addSubview(dimmedView)
dimmedView.frame = containerView.bounds
// Back animation
self.dimmedView.alpha = 0.8
Upvotes: 0