1

下面的代码允许用户在 imageView 上用两根手指向下滑动,从而呈现一个 popover/actionSheet。该过程运行良好。通常可以在弹出框/操作表之外点击以将其关闭。

问题是一旦弹出框/actionSheet 出现,它就不允许点击背景来关闭弹出框/actionSheet。您实际上需要在弹出框/actionSheet 内点击以将其关闭。

应用程序中还有其他地方会显示弹出框/actionSheet,但这些都是使用简单的按钮点击来显示的。

这是一个非常奇怪的场景。如果我在 imageView 上用 2 根手指轻扫并打开 popover/actionSheet,则无法在应用程序中的所有其他 popover/actionSheet 上点击背景。如果我绕过 imageView 上的 2 根手指滑动,所有其他 popover/actionSheet 都会正常工作。

除了呈现 popover/actionSheet 所需的代码之外,我已经删除了所有代码。我在 VC 和一个 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)
    }
}
4

0 回答 0