[UIView animateWithDuration:30.0f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
v.contentMode = UIViewContentModeScaleAspectFit;
v.frame = v.superview.bounds;
} completion:^(BOOL finished) {
[v removeFromSuperview];
}];
I want a UIImageView to resize and change the contentMode, but the code above doesn't work. It changed the contentMode immediately at the beginning of the animation.
Is there any way to animate it?
As others have mentioned there is no way to animate contentMode.
This library exists to solve that though! https://github.com/patrickbdev/PBImageView
imageView.contentMode = .scaleAspectFit
UIView.animateWithDuration(1) {
self.imageView.contentMode = .scaleAspectFill
}
Based on "What Can Be Animated", you cannot animate contentmode directly. However, you can try to animate the frame in order to get the same behavior as contentmode does. Once animation completed, you can set contentmode and frame back to original.
UIImageView
inherits its contentMode
property from UIView
. It is not one of the properties you can animate. More information can be found in the View Programming Guide.
To achieve that, you can use this component on github : https://github.com/VivienCormier/UIImageViewModeScaleAspect
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