Swift UIAlertController -> ActionSheet iPad iOS8 Crashes

前端 未结 8 1436
北恋
北恋 2020-12-02 12:20

currently i\'m running into big trouble with my ActionSheet. On iPhone it works great, but on iPad it only crashes

I create a new project with only one button

<
相关标签:
8条回答
  • 2020-12-02 12:46

    If someone uses sender : UITapGestureRecognizer this might be helpful.

    @objc func popupSettings(sender : UITapGestureRecognizer) {
        .....
        if let popoverPresentationController = alert.popoverPresentationController {
            popoverPresentationController.sourceView = self.view
            popoverPresentationController.sourceRect = CGRect(origin: sender.location(in: self.view), size: CGSize(width: 1.0, height: 1.0))
        }
        self.present(alert, animated: true, completion: nil)
    }
    
    0 讨论(0)
  • 2020-12-02 12:47
    var actionSheet = UIAlertController(title: "Please Select Camera or Photo Library", message: "", preferredStyle: .actionSheet)
    
    if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad ){
        actionSheet = UIAlertController(title: "Please Select Camera or Photo Library", message: "", preferredStyle: .alert)
    }
    
    actionSheet.addAction(UIAlertAction(title: "Upload a Photo", style: .default, handler: { (UIAlertAction) in
        self.openPhotoLibrary()
    }))
    actionSheet.addAction(UIAlertAction(title: "Take a Photo", style: .default, handler: { (UIAlertAction) in
        self.openCamera()
    }))
    actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
    self.present(actionSheet, animated: true, completion: nil)
    
    0 讨论(0)
提交回复
热议问题