操作 Sheet 在 ipad ios 13.6 中不起作用
Action Sheet is not working in ipad ios 13.6
我的应用程序将 UIAlertController 用于 ActionSheet 和 Alert。它在 iPad 中的 iOS 13.4 上工作正常,但如果我 运行 来自我的 iOS 13.6 设备的代码,这在 iPad 12.9 ios 13.6.
let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle:
UIAlertController.Style.actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedCamera(tag:2)
}))
alert.addAction(UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedGallery(tag:2)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (res) in
}))
if let popoverPresentationController = alert.popoverPresentationController {
popoverPresentationController.sourceView = sender
popoverPresentationController.sourceRect = sender.bounds
}
self.present(alert, animated: true, completion: nil)
尝试以下:
func showAlert(vc: UIViewController) {
let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: { (res) in
//TODO: your action
}))
alert.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { (res) in
//TODO: your action
}))
if let popoverController = alert.popoverPresentationController {
popoverController.sourceView = vc.view
popoverController.sourceRect = CGRect(x: vc.view.bounds.midX, y: vc.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
alert.dismiss(animated: true, completion: nil)
}
vc.present(alert, animated: true, completion: nil)
}
我已经在 iPhone(设备:- iPhone 11 Pro 13.6)和 iPad(iPad pro(12.9-第 4 代)两者都有效。但是如果你说,我已经更改了一些弹出框,请使用以下代码:-
let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle:
UIAlertController.Style.actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedCamera(tag:2)
}))
alert.addAction(UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedGallery(tag:2)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (res) in
}))
if let popoverPresentationController = alert.popoverPresentationController {
popoverPresentationController.sourceRect = sender.frame
popoverPresentationController.sourceView = self.view
}
self.present(alert, animated: true, completion: nil)
}
let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle:
UIAlertController.Style.actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedCamera(tag:2)
}))
alert.addAction(UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedGallery(tag:2)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (res) in
}))
if UIDevice.current.userInterfaceIdiom == .pad {
if let popup = alert.popoverPresentationController {
popup.sourceView = self.view
popup.sourceRect = CGRect(x: self.view.frame.size.width / 2, y: self.view.frame.size.height / 4, width: 0, height: 0)
}
}
}
self.present(alert, animated: true, completion: nil)
我的应用程序将 UIAlertController 用于 ActionSheet 和 Alert。它在 iPad 中的 iOS 13.4 上工作正常,但如果我 运行 来自我的 iOS 13.6 设备的代码,这在 iPad 12.9 ios 13.6.
let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle:
UIAlertController.Style.actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedCamera(tag:2)
}))
alert.addAction(UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedGallery(tag:2)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (res) in
}))
if let popoverPresentationController = alert.popoverPresentationController {
popoverPresentationController.sourceView = sender
popoverPresentationController.sourceRect = sender.bounds
}
self.present(alert, animated: true, completion: nil)
尝试以下:
func showAlert(vc: UIViewController) {
let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: { (res) in
//TODO: your action
}))
alert.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { (res) in
//TODO: your action
}))
if let popoverController = alert.popoverPresentationController {
popoverController.sourceView = vc.view
popoverController.sourceRect = CGRect(x: vc.view.bounds.midX, y: vc.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
alert.dismiss(animated: true, completion: nil)
}
vc.present(alert, animated: true, completion: nil)
}
我已经在 iPhone(设备:- iPhone 11 Pro 13.6)和 iPad(iPad pro(12.9-第 4 代)两者都有效。但是如果你说,我已经更改了一些弹出框,请使用以下代码:-
let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle:
UIAlertController.Style.actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedCamera(tag:2)
}))
alert.addAction(UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedGallery(tag:2)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (res) in
}))
if let popoverPresentationController = alert.popoverPresentationController {
popoverPresentationController.sourceRect = sender.frame
popoverPresentationController.sourceView = self.view
}
self.present(alert, animated: true, completion: nil)
}
let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle:
UIAlertController.Style.actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedCamera(tag:2)
}))
alert.addAction(UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default,
handler: { (res) in
self.btnClickedGallery(tag:2)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (res) in
}))
if UIDevice.current.userInterfaceIdiom == .pad {
if let popup = alert.popoverPresentationController {
popup.sourceView = self.view
popup.sourceRect = CGRect(x: self.view.frame.size.width / 2, y: self.view.frame.size.height / 4, width: 0, height: 0)
}
}
}
self.present(alert, animated: true, completion: nil)