当前位置: 首页 > 知识库问答 >
问题:

iPad上的ActionSheet崩溃(摄像头按钮)

农飞尘
2023-03-14

我的行动表有些问题。在iPhone上它工作正常,但在iPad上它只是崩溃了。

我有一个按钮来显示相机,但我不能在iPad上正确操作。

代码:

class pictureViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextViewDelegate {
    @IBOutlet weak var picture: UIImageView!
    override func viewDidLoad() {
    }

    @IBAction func choosePictureAction(sender: AnyObject) {
        let alertPictureFrom = UIAlertController(title: "De dónde sacar la foto?", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)
        presentViewController(alertPictureFrom, animated: true, completion: nil)
        alertPictureFrom.addAction(UIAlertAction(title: "Cámara", style: .Default, handler: {action in
            let picker = UIImagePickerController()
            picker.sourceType = .Camera
            picker.delegate = self
            picker.allowsEditing = true
            self.presentViewController(picker, animated: true, completion: nil)
        }))

        alertPictureFrom.addAction(UIAlertAction(title: "Galería", style: .Default, handler: {action in
            let picker = UIImagePickerController()
            picker.sourceType = .PhotoLibrary
            picker.delegate = self
            picker.allowsEditing = true
            self.presentViewController(picker, animated: true, completion: nil)
        }))
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
        picture.image = image
        picker.dismissViewControllerAnimated(true, completion: nil)
    }

}

您的应用程序提供了UIAlertController()风格的UIAlertControlllerStyleActionSheet。具有此样式的UIAlertController的modalPresentationStyle是UIModalPresentationPopover。您必须通过警报控制器的popoverPresentationController提供此弹出窗口的位置信息。您必须提供源视图和源Rect或barButtonItem。如果在显示警报控制器时不知道此信息,则可以在UIPopoverPresentationControlller委托方法-preareForPopoverPresations中提供。

共有3个答案

岑畅
2023-03-14

由于UIActionSheet导致的错误发生

ipad不支持UIActionSheet。对于iphone,在iphone UIActionsheet中无事可做对于IPAD,UIActionsheet可以在另一个视图中打开,如

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

它会为你工作。。。

戚奇略
2023-03-14

尝试(在UIButton的情况下):

picker.popoverPresentationController?.sourceView = testButton
picker.popoverPresentationController?.sourceRect = testButton.bounds
picker.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Right.bounds
艾阳羽
2023-03-14

正如错误消息所说:“您必须通过popoverPresentationController

这将允许UIKit知道从何处显示popover,然后您将获得一个可爱的行为,popover显示在您指定的元素上。

例如:

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

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

参考文件

  • popoverPresentationController
 类似资料:
  • 问题内容: 目前,我的ActionSheet遇到了大麻烦。在iPhone上效果很好,但在iPad上只会崩溃 我只用一个按钮创建一个新项目 正如我在iPhone上所说的那样,它可以工作,但是如果我单击iPad上的按钮,应用程序将崩溃, 2014-09-25 14:54:52.784 test [9541:1970048] 由于未捕获的异常“ NSGenericException”而终止应用程序,原因

  • 我正在开发一个应用程序,一个要求是用户可以从相机拍摄新照片或从图库中选择现有照片。我使用这个HTML5标签:

  • 表情测试 图片转文字 相框 拍摄图片

  • 摄像头用于采集图像和影像信息,通过模块间的组合完成各种创意活动。 净重量:8.1g 体积:24×24×22mm 参数 分辨率:1280×720 像素大小:3.4um×3.4um 最大图像传输速率:全尺寸 @ 30fps 视场角:100° 镜片结构:4G+IR 焦比:2.97 有效焦距:2.4mm 功耗:100uA(待机)~240mW(工作) 电源:USB总线电源 抗跌落能力:1m 工作温度:-30

  • 我正在尝试使用PC的内置网络摄像头在我的Android应用程序中拍照。我正在使用 eclipse Android 模拟器,并将 AVD 设置为使用 webcam0 作为后置摄像头,但是当我运行我的程序时,它总是崩溃,说“不幸的是,相机已停止”。我已将以下行添加到我的清单 xml 中: 尽管它似乎仍然不起作用。我在一些地方读到过,在AVD管理器的编辑/创建界面中应该有一个“硬件”部分,但是我的没有。

  • camera 对象提供对设备默认摄像头应用程序的访问。 方法: camera.getPicture 参数: cameraSuccess cameraError cameraOptions camera.getPicture 选择使用摄像头拍照,或从设备相册中获取一张照片。图片以base64编码的字符串或图片URI形式返回。 简单的范例: navigator.camera.getPicture( c