【问题标题】:UIAlertView not disabling all interactionUIAlertView 没有禁用所有交互
【发布时间】:2011-06-30 08:56:47
【问题描述】:

当 UIAlertView 显示时是否可以使用与其他窗口的交互。

我想到的解决方案是在 UIAlertView 窗口上增加一个额外的 UIWindow 或一个较小尺寸的警报。

有任何建议/解决方案如何实现这一目标?

谢谢

编辑:
我必须使用 UIAlertView 实例。我已经找到了一种方法来识别显示 UIAlertView 的时刻。

【问题讨论】:

    标签: iphone objective-c xcode ipad uialertview


    【解决方案1】:

    只需一个想法,使用您的警报文本和按钮创建自定义视图并将其显示为 UIAlertView。单击按钮隐藏该视图。这将解决您的目的。您可以使用以下代码。请根据您的要求调整 x/y/高度/宽度。

    UIView *customAlert = [[UIView alloc] initWithFrame:CGRectMake(100,100,100,100)];
    UILabel *lblText = [[UILabel alloc] initWithFrame:CGRectMake(0,0,100,30)];
    lblText.text =@"Your alert text";
    
    [customAlert addSubView:lblText];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self action:@selector(hideAlertView:) forControlEvents:UIControlEventTouchDown];
    [button setTitle:@"OK" forState:UIControlStateNormal];
    button.frame = CGRectMake(30.0, 50.0, 50.0, 50.0);
    [customAlert addSubview:button];
    
    [self.view addSubView:customAlert];
    
    -(IBAction)hideAlertView:(id)sender
    {
         [customAlert removeFromSuperView];
    }
    

    编辑

    由于 UIAlertView 具有 MODAL 行为,因此在将其关闭之前,您无法触摸应用程序的任何其他部分。

    【讨论】:

    • 好的。那将是我的正常解决方案,但我必须使用 UIAlertView 实例。我将编辑我的问题。
    • 我看到了你的解决方案。就像我说的,我通常会使用它。但是您不使用 UIAlertView 并且我 必须 (非常糟糕)...所以我的问题是,可以在模态 UIAlertView 上放置一个视图/窗口吗?
    【解决方案2】:

    快速解决方案:

      // Define a view
      var popup:UIView!
      func showAlert() {
        // customise your view
        popup = UIView(frame: CGRect(x: 100, y: 200, width: 200, height: 200))
        popup.backgroundColor = UIColor.redColor()
    
        // show on screen
        self.view.addSubview(popup)
    
      }
    
      func dismissView(){
        // Dismiss the view from here
        popup.removeFromSuperview()
      }
    

    【讨论】:

      猜你喜欢
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多