Can I setup a function to be called once my animation is complete? I want to fade a UIView
and then remove it from the superView
.
withAnimation() takes a parameter specifying the kind of animation you want, so you could create a three-second linear animation like this: withAnimation(.linear(duration: 3)) Explicit animations are often helpful because they cause every affected view to animate, not just those that have implicit animations attached.
To be exact, whenever you want to animate the view, you actually call layoutIfNeeded on the superview of that view. Try this instead: UIView. animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.
SwiftUI has built-in support for animations with its animation() modifier. To use this modifier, place it after any other modifiers for your views, tell it what kind of animation you want, and also make sure you attach it to a particular value so the animation triggers only when that specific value changes.
Animation blocks were introduced in iOS4. Apple recommends you use these, and the new methods mostly ask for completion blocks which replace callbacks. For example:
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseInOut
animations:^{
[myView setAlpha:0.0f];
}
completion:^(BOOL finished) {
[myView removeFromSuperview];
}];
Yes, that's easy:
When you configure your animation
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(myAnimationStopped:finished:context:)];
And define your method like:
-(void)myAnimationStopped:(NSString *)animationID
finished:(NSNumber *)finished
context:(void *)context {
// fancy code here
}
Doesn't have to be self
and that method, of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With