1

有一个基本形式,按下按钮调用方法performSegueWithIdentifier,显示弹出窗口。在弹出框处于活动状态之前,如何使主视图窗口变黑(变暗)?

我尝试像这样使用库SVProgressHUD

- (IBAction)publishButtonAction:(id)sender {
    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
    [self performSegueWithIdentifier:@"fbshareSigue" sender:self];
    [SVProgressHUD dismiss];
}

获得一瞬间 - 直到有一个弹出窗口。

如果我尝试这个,我必须在哪里插入这个代码?:

- (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];
        }
    }*/

昏暗的不行...

=====================

我有 ViewOFAResultViewController调用 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];    
}
...

OFAFBShareViewController我试图关闭昏暗的视图:

...
- (IBAction)cancelButtonAction:(id)sender {
    [closePopWindow dismissPopoverAnimated:YES];
    for (UIView *view in [self.view subviews]) {
            if (view.tag == 1111) {
                [view removeFromSuperview];
            }
}
...

但是又不行了……

4

2 回答 2

2

当您显示弹出窗口时,您可以使用以下代码。

在 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];
}

删除弹出窗口后,使用标签从超级视图中删除此视图。

iOS 5.0 之后还引入了公共 API 方法:

==================================================== ====

要删除视图,您可以使用以下代码:

 for (UIView *view in [self.view subviews]) {
                if ([view.tag == 1111]) {
                    [view removeFromSuperview];
                }
            }

保留您的 Remove Dim View 代码不变。super.view只能再次更改self.view

那它会为你工作。

希望这对你有用...

于 2012-10-30T13:07:49.877 回答
0

创建弹出框时,在当前视图中添加一个暗淡的视图,并将当前视图添加为弹出框控制器的 UIPopoverControllerDelegate:

  1. 添加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)
    
  2. 添加原始视图作为 popoverController 的委托:

    popoverViewController!.delegate = self
    

然后,为了在 popover 关闭时移除 dimView,将当前视图设置为实现 UIPopoverControllerDelegate,并实现 popoverControllerDidDismissPopover 函数。在此函数中,删除 dimView:

extension MyOriginViewController: UIPopoverControllerDelegate {

    func popoverControllerDidDismissPopover(popoverController: UIPopoverController) {
        for subView in view.subviews {
            if subView.tag == 1234 {
                 subView.removeFromSuperview()
            }
        }
    }
}    
于 2015-06-03T18:37:39.003 回答