// You can use it with all kind of UIViews e.g. UIButton, UILabel, UIImage, UIImageView, ...
imageView.flash(animation: .opacity, withDuration: 1, repeatCount: 5)
titleLabel.flash(animation: .opacity, withDuration: 1, repeatCount: 5)
UIViewAnimationOptions set provides different handy options to achieve a combination of beautiful and complex animations. For your particular scenario you will require two of the options.
Explanation:
I have created a view with a specific frame for demo purpose.
The part you are interested in is the UIView.animateWithDuration method. Notice that I have provided an array [UIViewAnimationOptions.AutoReverse, UIViewAnimationOptions.Repeat] in the options parameter.
If you want repeatable fade animation you can do that by using
CABasicAnimation
like below :First create handy UIView extension :
How to use it:
I assume you are programming for iOS.
Play around with the
duration
to see what suits you best:For iOS
UIViewAnimationOptions set provides different handy options to achieve a combination of beautiful and complex animations. For your particular scenario you will require two of the options.
Check out the code below for implementation.
Code:
Explanation: I have created a view with a specific frame for demo purpose.
The part you are interested in is the
UIView.animateWithDuration
method. Notice that I have provided an array[UIViewAnimationOptions.AutoReverse, UIViewAnimationOptions.Repeat]
in theoptions
parameter.These two options are enough to achieve a smooth and forever looping animation like below. https://s3.amazonaws.com/uploads.hipchat.com/37040/1764070/6Iow7n7WiWf6Naz/autoReverse.gif
If you don't want to reverse the animation, just remove
UIViewAnimationOptions.AutoReverse
from the array in theoptions
parameter. You will get an animation like this. https://s3.amazonaws.com/uploads.hipchat.com/37040/1764070/8fyRUlzqNHSQI47/noreverse.gifFor iOS
let
viewSquare
be the name of the blue square in your question.