iPad上的ActionSheet崩溃(相机按钮)

时间:2015-12-15 13:23:20

标签: ios swift ipad uialertcontroller

我的ActionSheet遇到了一些麻烦。在iPhone上它工作正常,但在iPad上它只是崩溃。

我有一个显示相机的按钮,但我无法在iPad上正确显示。

代码:

$.plotAnimate()
  

您的应用程序提供了样式UIAlertControllerStyleActionSheet的UIAlertController()。具有此样式的UIAlertController的modalPresentationStyle是UIModalPresentationPopover。您必须通过警报控制器的popoverPresentationController为此弹出窗口提供位置信息。您必须提供sourceView和sourceRect或barButtonItem。如果在显示警报控制器时不知道此信息,您可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供它。

3 个答案:

答案 0 :(得分:3)

正如错误消息所示:"您必须提供sourceView和sourceRect或barButtonItem"通过popoverPresentationController

这将允许UIKit知道弹出窗口的位置,然后你会得到弹出窗口附加到你指定元素的可爱行为。

例如:

alertPictureFrom.popoverPresentationController?.sourceRect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
alertPictureFrom.popoverPresentationController?.sourceView = self.view

现在该示例完全用于演示目的,您需要为弹出窗口找出sourceViewsourceRect

参考文档:

答案 1 :(得分:0)

尝试(在UIButton的情况下):

picker.popoverPresentationController?.sourceView = testButton
picker.popoverPresentationController?.sourceRect = testButton.bounds
picker.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Right.bounds

答案 2 :(得分:0)

由于UIActionSheet而产生的错误代数

  

UIActionSheet不支持ipad。   对于iphone无关,在iphone UIActionsheet工作正常   对于IPAD UIActionSheet在另一个视图中打开,如

UIActionSheetObjects.showFromRect(CGRectMake(150, 0, 300,200 ) ,inView:self.view, animated:YES)

它会对你有用......

相关问题