Reputation: 2681
There is a basic form, pressing button call method performSegueWithIdentifier
which shows the popover window. How could I black out (dim) the main view window until the popover is active?
I've tried to use the library SVProgressHUD like this:
- (IBAction)publishButtonAction:(id)sender {
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
[self performSegueWithIdentifier:@"fbshareSigue" sender:self];
[SVProgressHUD dismiss];
}
Obtained for a split second - until there is a popover-window.
Where must I insert this code, if I try this?:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"fbshareSigue"]) {
OFAFBShareViewController *svc = (OFAFBShareViewController *) [segue destinationViewController];
UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue *)segue;
svc.postBlock = self.postInitBlock;
[svc setClosePopWindow:[popoverSegue popoverController]];
}
}
- (IBAction)publishButtonAction:(id)sender {
UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.5f;
dimView.tag = 1111;
dimView.userInteractionEnabled = NO;
[self.view addSubview:dimView];
[self performSegueWithIdentifier:@"fbshareSigue" sender:self];
}
/* This code should be put in the other method where you are removing the popup.. Because it will remove the dim view. here is the wrong place for this code*/
/* for (UIView *view in [self.view subviews]) {
if (view.tag == 1111) {
[view removeFromSuperview];
}
}*/
Dim doesn't work...
====================
I have View OFAResultViewController
that calling Popover (OFAFBShareViewController
):
...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"fbshareSigue"]) {
OFAFBShareViewController *svc = (OFAFBShareViewController *) [segue destinationViewController];
UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue *)segue;
svc.postBlock = self.postInitBlock;
[svc setClosePopWindow:[popoverSegue popoverController]];
}
}
- (IBAction)publishButtonAction:(id)sender {
UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.5f;
dimView.tag = 1111;
dimView.userInteractionEnabled = NO;
[self.view addSubview:dimView];
[self performSegueWithIdentifier:@"fbshareSigue" sender:self];
}
...
In OFAFBShareViewController
I'm trying to close the dim view:
...
- (IBAction)cancelButtonAction:(id)sender {
[closePopWindow dismissPopoverAnimated:YES];
for (UIView *view in [self.view subviews]) {
if (view.tag == 1111) {
[view removeFromSuperview];
}
}
...
But it doesn't work again...
Upvotes: 1
Views: 3656
Reputation: 1648
When you create the popover, add a dim view to the current view, and add the current view as a UIPopoverControllerDelegate of the popover controller:
Add the dimView:
let dimView = UIView(frame: view.frame)
view.addSubview(dimView)
dimView.backgroundColor = UIColor.blackColor()
dimView.alpha = 0.5
dimView.tag = 1234
dimView.userInteractionEnabled = false
view.addSubview(dimView)
Add the origin view as delegate of the popoverController:
popoverViewController!.delegate = self
Then, in order to remove the dimView when the popover is dismissed, set the current view as implementing the UIPopoverControllerDelegate, and implement the popoverControllerDidDismissPopover func. Inside this function, remove the dimView:
extension MyOriginViewController: UIPopoverControllerDelegate {
func popoverControllerDidDismissPopover(popoverController: UIPopoverController) {
for subView in view.subviews {
if subView.tag == 1234 {
subView.removeFromSuperview()
}
}
}
}
Upvotes: 0
Reputation: 1506
You can use the following code, when you display the popup.
In OFAFBShareViewController
- (void) loadView
{
[super loadView];
UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.5f;
dimView.tag = 1111;
dimView.userInteractionEnabled = NO;
[self.view addSubview:dimView];
}
After popup removed, delete this view from super view using the tag.
After iOS 5.0 there is a public API method also introduced:
======================================================
To remove the view you can use this code:
for (UIView *view in [self.view subviews]) {
if ([view.tag == 1111]) {
[view removeFromSuperview];
}
}
Leave your Remove Dim View code as it is. Only Change super.view
to self.view
again.
It'll work for you then.
Hope it works for you...
Upvotes: 2