1

The code below allows the user to do a 2 finger swipe down on an imageView and thus presenting a popover/actionSheet. That process works fine. Normally it is possible to tap outside the popover/actionSheet to close it.

The problem is that once the popover/actionSheet is presented, it doesn't allow tapping the background to close the popover/actionSheet. You actually need to tap inside the popover/actionSheet to close it.

There are other places in the app that present a popover/actionSheet but these are presented using a simple button tap.

Here's the really weird scenario. If I do the 2 finger swipe on the imageView and open the popover/actionSheet, the inability to tap the backGround is broken on all the other popover/actionSheet in the app too. If I bypass the 2 finger swipe on the imageView all of the other popover/actionSheet work as normal.

I've stripped out all the code other than what's needed to present the popover/actionSheet. And I created a new project with on VC and one imageView so as to eliminate any possible conflict with cocoa pod, etc. What is wrong with this code?

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)
    }
}
TylerP
  • 9,600
  • 4
  • 39
  • 43
Quailcreek
  • 125
  • 2
  • 9
  • After more testing it looks like this is a problem only on the sim. I have tested it on a XS MAX and a 6s and it works as expected. However, I do not have an iPad to test on. Could someone with an iPad please test my sample code and let me know if it works. I would be very grateful. – Quailcreek May 16 '20 at 21:27

0 Answers0