uiimageview animationImages with uiimage" resizableImageWithCapInsets"

时间:2013-11-11 11:09:36

标签: ios objective-c uiimageview resize uiimage

好吧,我有一个UIImageView,我希望通过“animationImages”为其图像制作动画,如下所示:

UIImage *img1 = [[UIImage imageNamed:@"image1.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 150, 20, 150)];
UIImage *img2 = [[UIImage imageNamed:@"image2.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 150, 20, 150)];
self.imgStatus.animationImages = [NSArray arrayWithObjects:img1, img2, nil];
self.imgStatus.animationDuration = 1;
self.imgStatus.contentMode = UIViewContentModeScaleToFill;
[self.imgStatus startAnimating];

两个图像的宽度小于UIImageView的宽度,所以我希望在动画显示时调整这些图像的大小。但是动画不会使用“resizableImageWithCapInsets”进行任何重新设置,只需缩放它们以填充UIImageView的帧。

有什么想法吗?我该怎么办?

谢谢!

1 个答案:

答案 0 :(得分:1)

嗯,我发现的解决方案是在开始动画之前必须调整阵列的所有UIImages。因此,我使用一个类似于setter“setAnimationImages”的过程创建了这个类的UIImageView,但在其中所有UIImages都由UIImageView框架调整大小。 UIImageView的“ContentMode”属性也设置为“UIViewContentModeScaleToFill”。

最后,每个UIImage之前设置“resizableImageWithCapInsets”非常重要,以了解如何调整每个。(/ p>

示例:

#import "UIImageView+AnimationImages.h"

UIImage *img1 = [[UIImage imageNamed:@"image1.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 150, 20, 150)];
UIImage *img2 = [[UIImage imageNamed:@"image2.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 150, 20, 150)];

[self.imgView setAnimationImagesWithUIImageViewSize:[NSArray arrayWithObjects:img1, img2, nil]];

self.imgView.animationDuration = 1;

[self.imgView startAnimating];

您可以找到此类别(UIImageView + AnimationImages)here

相关问题