UIAlertView不会禁用所有交互

时间:2011-06-30 08:56:48

标签: iphone objective-c xcode ipad uialertview

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

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

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

由于

修改
我必须使用UIAlertView实例。我已经找到了一种方法来识别显示UIAlertView的那一刻。

2 个答案:

答案 0 :(得分:1)

只需创建一个包含警报文本和按钮的自定义视图,并将其显示为UIAlertView。单击按钮可隐藏该视图。哪个会解决你的目的。在Code下面你可以使用相同的代码。 Plz根据您的要求调整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行为,因此在解除之前您无法触及应用程序的任何其他部分。

答案 1 :(得分:0)

Swift Solution:

  // 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()
  }