I'm making a notification bar to fade in and fade out again at the top of my view. I've added a tap gesture recogniser so that when the user clicks the notification when it's showing, it can take him to that update or whatever.
UIView.animateWithDuration(0.8, animations: {
self.navigationViewController.notificationView.view.alpha = 1.0
}, completion: { finished in
UIView.animateWithDuration(0.8, delay: 5.0, options: .CurveLinear, animations: {
// This line below prevents the tap gesture from ever being recognized
self.navigationViewController.notificationView.view.alpha = 0.0
}, completion: nil)
})
}
As you can see, the update fades in, shows for 5 seconds then fades out. When I remove the commented line, everything works fine and the gesture is recognised, but when I uncomment it, for some reason, when it's visible, the gesture recogniser won't recognise any taps.
Here's the code for defining the view and the recogniser:
// notificationView view controller:
override func viewDidLoad() {
super.viewDidLoad()
tap = UITapGestureRecognizer(target: self, action: "tapped")
self.view.addGestureRecognizer(tap)
tap.numberOfTouchesRequired = 1
tap.numberOfTapsRequired = 1
tap.cancelsTouchesInView = false
}
I don't know if it makes any difference or not, but the view is being displayed over a navigation view controller, so I'm not able to use the addchildviewcontroller method to add the view without it adding it as a page. I don't think this is the issue though as it works with the line uncommented.
I've also done
notificationView.view.userInteractionEnabled = true
which doesn't seem to help.
Thanks in advance!
EDIT: I've distilled the problem down to this sample project: https://github.com/magicmark/SwiftAnimationProblem
You can see the problem clearly here. Is this another swift bug maybe?
EDIT 2: I've done a version in Objective C. Same problem!