iPadでActionSheetを表示する

f:id:machinemxy:20200825233226p:plain iPadでActionSheetを正しく呼び出す元の近くで表示させるため、popoverPresentationControllerのsourceViewとsourceRectの設定が必要です。
例:

@IBAction func dataPressed(_ sender: UIButton) {
    let ac = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
    ac.addAction(UIAlertAction(title: "Save", style: .default, handler: nil))
    ac.addAction(UIAlertAction(title: "Load", style: .default, handler: nil))
    ac.addAction(UIAlertAction(title: "Restart From Beginning", style: .destructive, handler: nil))
    ac.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
    ac.popoverPresentationController?.sourceView = sender
    ac.popoverPresentationController?.sourceRect = sender.bounds
    present(ac, animated: true)
}