无论如何将UIImageView的contentMode从aspectFill动画到aspectFit?

ada*_*ali 4 animation uiimageview ios

[UIView animateWithDuration:30.0f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
    v.contentMode = UIViewContentModeScaleAspectFit;
    v.frame = v.superview.bounds;
} completion:^(BOOL finished) {
    [v removeFromSuperview];
}];
Run Code Online (Sandbox Code Playgroud)

我想要一个UIImageView调整大小并更改contentMode,但上面的代码不起作用.它在动画开始时立即更改了contentMode.

有什么方法可以动画吗?

Pat*_*ick 8

正如其他人所提到的,没有办法为contentMode制作动画.

这个库的存在是为了解决这个问题! https://github.com/patrickbdev/PBImageView

imageView.contentMode = .scaleAspectFit

UIView.animateWithDuration(1) {
    self.imageView.contentMode = .scaleAspectFill
}
Run Code Online (Sandbox Code Playgroud)


Jin*_*wei 5

基于" 可以动画的内容 ",您无法直接为内容模式制作动画.但是,您可以尝试设置框架的动画,以获得与contentmode相同的行为.动画完成后,您可以将contentmode和frame设置回原始状态.


Mis*_*Moo 2

UIImageView继承其contentMode属性UIView。它不是您可以设置动画的属性之一。更多信息可以在视图编程指南中找到。