I have my background image set by self.view.insertSubview. I'm trying to create a UISwipeGestureRecognizer that advances through the background Image on swipe, while another image array cycles on tap. The tap image works fine but the swipe image only works on the first swipe.
Here's the gesture recognizer:
let gestureRecognizerBackground = UISwipeGestureRecognizer(target: self, action: #selector(changeBackground))
dragon2View.addGestureRecognizer(gestureRecognizerBackground)
and here's the changeBackground func:
func changeBackground() {
let backgroundImageArray = [#imageLiteral(resourceName: "artic.png"),#imageLiteral(resourceName: "beach.png"),#imageLiteral(resourceName: "mountain.jpg"),#imageLiteral(resourceName: "spring.png")]
let randomBackground = Int(arc4random_uniform(UInt32 (backgroundImageArray.count)))
let backgroundImage = UIImageView(frame: UIScreen.main.bounds)
backgroundImage.image = backgroundImageArray[randomBackground]
self.view.insertSubview(backgroundImage, at: 0)
}
Not sure why it's not advancing. Thanks in advance for your comments.