1
votes

I have several UIView extensions that I call from a tap gesture recognizer. Why does the background color extension have to finish animating before additional taps can be recognized? The alpha extension plus another one I use to animate the position of a view work just fine - meaning I can tap as quickly as I want and they respond immediately.

@IBAction func taps(sender: UITapGestureRecognizer) {
   if !isAnimating {
      currentLabel.fadeOut()
      backgroundColor.fadeBackgroundOut()
      isAnimating = true   
   } else {
      currentLabel.fadeIn()
      backgroundColor.fadeBackgroundIn(curBackground)
      isAnimating = false
   }
}

func fadeOut() {
   UIView.animateWithDuration(0.5,
      delay: 0.0,
      options: UIViewAnimationOptions.CurveEaseOut,
      animations: { self.alpha = 0.0 },
      completion: nil)
}

func fadeBackgroundIn(aColor: UIColor) {
   UIView.animateWithDuration(1.0,
      delay: 0,
      options: UIViewAnimationOptions.CurveEaseIn,
      animations: { self.backgroundColor = aColor },
      completion: nil)
}
2

2 Answers

3
votes

Update your extension as:

func fadeOut() {
   UIView.animateWithDuration(0.5,
      delay: 0.0,
      options: [UIViewAnimationOptions.CurveEaseIn , UIViewAnimationOptions.AllowUserInteraction],
      animations: { self.alpha = 0.0 },
      completion: nil)
}

func fadeBackgroundIn(aColor: UIColor) {
    UIView.animateWithDuration(1.0,
        delay: 0,
        options: [UIViewAnimationOptions.CurveEaseIn , UIViewAnimationOptions.AllowUserInteraction],
        animations: { self.backgroundColor = aColor },
        completion: nil)
}
0
votes

That's very easy thing, you must understand if you change the alpha of "self" i.e view to zero it stops getting touch events.

What can be nice solution is to "self" i.e view's background color to transparent, instead of changing "self" i.e view's alpha value, by that your view won't be visible and you get the gesture recognizer events.

Alternative solution can be, to adding a transparent button on the view, handle the button tap action.