Reputation: 23
I'm new to programming, so please excuse any lack of clarity. I'm trying to make one of my buttons have a "blinking effect" using the animateWithDuration method. Currently, it works as a "fade," where the button gradually shows up and disappears every 1 second (I set the duration to be 1.0). I'm hoping to reduce the speed of the animation (not the duration, but the speed), so that the animation effect would occur more abruptly. The interval of the animation needs to stay at every 1 second. Is this possible to accomplish? I've been researching, and it seems like animateWithDuration doesn't allow this sort of specification... Do I need to approach this via another method? I'm including my code below. Thanks for your help! Btw, this is all under UIViewController in UIKit.
override func viewDidLoad() {
super.viewDidLoad()
self.tapButton.alpha = 0
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
UIView.animateWithDuration(1.0, delay: 0, options: .Repeat | .AllowUserInteraction | .Autoreverse, animations: { () -> Void in self.tapButton.alpha = 1.0
}, completion: nil )
}
Upvotes: 1
Views: 6461
Reputation: 6824
Try adding Curve related options:
UIViewAnimationOptions.CurveEaseOut
UIViewAnimationOptions.CurveEaseIn
UIViewAnimationOptions.CurveEaseInOut
Being ..as of Apple Documentation:
EaseInOut An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing. This is the default curve for most animations.
EaseIn An ease-in curve causes the animation to begin slowly, and then speed up as it progresses.
EaseOut An ease-out curve causes the animation to begin quickly, and then slow down as it completes.
so, it would end like stated below this point:
UIView.animateWithDuration(1.0, delay: 0, options: .Repeat | .AllowUserInteraction | .Autoreverse | UIViewAnimationOptions.CurveEaseOut, animations: { [weak self] in
self?.tapButton.alpha = 1.0
}, completion: nil)
Upvotes: 7
Reputation: 1323
Put the animation on a repeating 1second NSTimer and decrease the duration of the animation.
Upvotes: 0