以下のコードでは、ユーザーが imageView を 2 本の指で下にスワイプして、ポップオーバー/アクションシートを表示できるようにします。そのプロセスはうまくいきます。通常、ポップオーバー/アクションシートの外側をタップして閉じることができます。
問題は、ポップオーバー/アクションシートが表示されると、背景をタップしてポップオーバー/アクションシートを閉じることができないことです。ポップオーバー/アクションシートを閉じるには、実際にタップする必要があります。
ポップオーバー/アクション シートを表示するアプリ内の他の場所がありますが、これらは単純なボタン タップを使用して表示されます。
これが本当に奇妙なシナリオです。imageView で 2 本の指をスワイプして popover/actionSheet を開くと、アプリ内の他のすべての popover/actionSheet でも backGround をタップできなくなります。imageView で 2 本指のスワイプをバイパスすると、他のすべての popover/actionSheet は通常どおり機能します。
ポップオーバー/アクション シートを表示するために必要なもの以外のすべてのコードを取り除きました。そして、VC と 1 つの imageView を使用して新しいプロジェクトを作成し、ココア ポッドなどと競合する可能性を排除しました。このコードの何が問題なのですか?
class ViewController: UIViewController
{
@IBOutlet weak var imageView_Outlet: UIImageView!
override func viewDidLoad()
{
super.viewDidLoad()
imageView_Outlet.isUserInteractionEnabled = true
let swipeGuesture = UISwipeGestureRecognizer(target: self, action: #selector(imageViewSwiped(recognizer:)))
swipeGuesture.numberOfTouchesRequired = 2
swipeGuesture.direction = .down
imageView_Outlet.addGestureRecognizer(swipeGuesture)
}
@objc func imageViewSwiped(recognizer: UISwipeGestureRecognizer)
{
let theAlert = UIAlertController(title: "Welcome Image", message: "Only one image can be saved as your welcome screen. The current image will automatically be replaced." , preferredStyle: .actionSheet)
let chooseImage = UIAlertAction(title: "Choose a New Image", style: .default, handler: { (okAction) in
})
let deleteBtn = UIAlertAction(title: "Delete the Current Image", style: .destructive, handler: { (deleteAction) in
})
let cancelBtn = UIAlertAction(title: "Cancel", style: .cancel) { (cancelAction) in
}
theAlert.addAction(cancelBtn)
theAlert.addAction(chooseImage)
theAlert.addAction(deleteBtn)
let popOver = theAlert.popoverPresentationController
popOver?.sourceView = self.imageView_Outlet
popOver?.sourceRect = self.imageView_Outlet.bounds
popOver?.permittedArrowDirections = .any
present(theAlert, animated: true)
}
}