PlugInBoy PlugInBoy - 8 months ago 49
Swift Question

Fade In and Fade out in Animation Swift

I have an UIImageView with an Animation and, in the UIView, I apply a fadeIn effect, but I need to apply fade out when the UIImageView, which is animated, when is touched.

This is what I make to fade in.

UIView.animateWithDuration(0.5, delay: delay,
options: UIViewAnimationOptions.CurveEaseOut, animations: {
uiImageView.alpha = 1.0


This is what I would do based on my research: (Supposing you're using storyboard)

  1. Go to your UIImageView, and under the Attributes, check the "User Interaction Enabled" checkbox.

  2. Drag a TapGestureRecognizer on top of the image view.

  3. Control click on the Tap Gesture and drag to make a action on your ViewControler.swift.

  4. Add the following code inside:

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

Then you're done!