2014-10-28 84 views
1

我必須使用UIAlertController顯示帶有選取器,取消和完成按鈕的視圖。這是我寫的代碼:UIAlertController禁用屏幕上的所有觸摸事件

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet]; 
     UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil]; 
     [alertController addAction:alertAction]; 
     [alertController.view addSubview:pickerView]; 
     [alertController.view addSubview:cancelBtn]; 
     [alertController.view addSubview:doneBtn]; 
     [alertController.view setBounds:CGRectMake(0, 180, self.view.frame.size.width, 400)]; 

,這是我如何調用本視圖控制器方法:

UIPopoverPresentationController *popover = alertController.popoverPresentationController; 
     if (popover) 
     { 
      popover.sourceRect = CGRectMake(0, 0, 320, 550); 
      popover.permittedArrowDirections = UIPopoverArrowDirectionAny; 
     } 
[self presentViewController:alertController animated:YES completion:nil]; 

報警控制器屏幕後出現在屏幕上,我無法利用上取消並完成按鈕以及屏幕上的任何位置。請幫我解決這個問題。

沒有設置界定取消和done按鈕出現在頁面的底部: enter image description here

每當我設置範圍至alertcontroller,我能看到正確的觀點,但不能選擇什麼: enter image description here

+0

你知道嗎? – Markymark 2016-08-31 20:07:40

回答

0

我敢打賭你的界限是不正確的。所以這行:

[alertController.view setBounds:CGRectMake(0,180,self.view.frame.size.width,400)];

是設置你的觀點邊界在180

編輯開始:基於以下的意見,如果你想設置的按鈕位置,你應該修改你的按鈕幀,而不是alertview界限。

記住框架是根據父視圖座標系統的視圖位置。邊界是與其自己的座標系相關的視角限制。

+0

我已驗證。邊界寬度不爲0. – Dee 2014-10-28 09:03:44

+0

在presentViewController完成時添加一個塊,以打印視圖邊界和大小。點擊未被檢測到的問題通常與邊界有關。 – CarlesCF 2014-10-28 09:18:11

+0

已添加。我設置的值正在打印。 – Dee 2014-10-28 09:36:50