【问题标题】:uiimageview animationImages with uiimage "resizableImageWithCapInsets"带有 uiimage "resizableImageWithCapInsets" 的 uiimageview 动画图像
【发布时间】:2013-11-11 11:09:35
【问题描述】:

好吧,我有一个 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 的框架。

你知道吗?我该怎么做?

谢谢!!

【问题讨论】:

    标签: ios objective-c uiimageview resize uiimage


    【解决方案1】:

    好吧,我找到的解决方案是在开始动画之前必须调整数组的所有 UIImages 的大小。因此,我使用类似于 setter "setAnimationImages" 的过程创建了此类 UIImageView,但在其中所有 UIImage 都由 UIImageView 框架调整大小。 UIImageView 的“ContentMode”属性也设置为“UIViewContentModeScaleToFill”。

    最后,每个 UIImage 之前都设置了“resizableImageWithCapInsets”以知道如何调整每个 UIImage 的大小,这一点非常重要。

    例子:

    #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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-29
      • 1970-01-01
      相关资源
      最近更新 更多