禁用所有交互的UIView控制器,当推出新的UIView时

3

我在这里使用这段代码UIView Popup like UIAlertView来创建与UIalertView相同的UIVIew。 我从UIViewController中推出新的UIViewAlert,但是我希望UIViewAlert出现时,UIViewController不需要点击或选择,然后UIViewAlert消失时,UIViewController可以正常点击。 在我的ViewController中有1个tablview,1个包含4个UIButton的tabbar。

我将新的UIViewAlert命名为:

    DetailView *detailAlert = [[DetailView alloc] init];
    [self.view addSubview:detailAlert];
    [detailAlert show];
    [detailAlert release];

有人能给我展示一下吗?谢谢。
3个回答

1
您可以通过在启动警报视图之前添加 BLOCK SCREEN 来实现此目的,请参见下面的代码。
self.blockView=[[UIView alloc] initWithFrame:self.view.frame];
self.blockView.backgroundColor = [UIColor blackColor];
self.blockView.alpha = .5;
self.blockView.userInteractionEnabled=NO;
[self.view addSubview:self.blockView];

DetailView *detailAlert = [[DetailView alloc] init];
[self.view addSubview:detailAlert];
[detailAlert show];
[detailAlert release];

当您移除警报视图时,请执行以下操作。
[self.blockView removeFromSuperview];

谢谢,我尝试了你的代码,但它是一个视图,无法禁用视图控制器的交互。 - HTKT611
在将其添加到self.view之后,尝试添加[self.view bringSubviewToFront:self.blockView]; - iphonic

0

谢谢,但如果您点击背景,它将会消失。如果我想要点击按钮,它会消失吗? - HTKT611
请在 UIViewController+MJPopupViewController.m 文件中注释掉以下行://[dismissButton addTarget:self action:@selector(dismissPopupViewControllerWithanimation:) forControlEvents:UIControlEventTouchUpInside]; - ChandreshKanetiya
它可以用于UIVIew而不是UIVIewController吗? - HTKT611
你可以使用UIViewController代替UIView。 - ChandreshKanetiya

0

您可以创建一个清晰的视图控制器并以模态方式呈现它,以下是Swift 2的示例:

private func TransparentViewController() -> UIViewController {
  let transparentViewController = UIViewController(nibName: nil, bundle: nil)
  transparentViewController.modalPresentationStyle = .OverCurrentContext
  transparentViewController.modalTransitionStyle = .CrossDissolve
  transparentViewController.view.backgroundColor = UIColor.clearColor()
  return transparentViewController
}

现在你可以在展示 HUD 之前从你的视图控制器中呈现它:

let transparentViewController = TransparentViewController()
self.presentViewController(transparentViewController, animated:false, completion: nil) 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接