【问题标题】:Source image and UIImage are different sizes源图像和 UIImage 大小不同
【发布时间】:2012-11-14 07:02:09
【问题描述】:

所以我正在使用 UIImageView 为一组图像设置动画。它有效,但事情正在奇怪地调整大小。我在扩展的 UIImageView 类中初始化所有内容,如下所示:

tImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",tName]];
self = [self initWithImage: tImage];

NSMutableArray *frameArray = [[NSMutableArray alloc] initWithCapacity:0];
UIImage *tFrame;

    for(int i = 1; i < prp.frames + 1; i++) {
        tFrame = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.png", tName, i]];
        [frameArray addObject:tFrame];
    }

CGRect cropRect = CGRectMake(0.0, 0.0, tFrame.size.width, tFrame.size.height);
self.bounds = cropRect;
[self setContentMode:UIViewContentModeScaleAspectFit];
self.clipsToBounds = YES;

[self setAnimationImages:frameArray];
[self setAnimationDuration:prp.frameDur];
[self startAnimating];

prp.framesprp.frameDur 是我从自定义属性结构中传入的值。

我遇到的问题是图像的大小在每个阶段都不同。我的源图像都是 59x47。 tImage (UIImage) 设置为 46x26(检查 size.width 和 size.height 属性)。 tFrame (UIImage) 设置为 53x35(检查相同的属性)。有谁知道为什么会发生这种情况?为什么不初始化为原始图像大小(59x47),为什么基于它们的两个UIImage对象会互不相同??

【问题讨论】:

    标签: ios uiimageview uiimage png


    【解决方案1】:

    我自己想出来的。我已通过替换将与 tImage 一起使用的源图像从 46x26 大小更改为 59x47(两者之间的图像名称相同)。它仍在使用 46x26 图像,在缓存中或我猜的东西中。我通过清理和重建项目来修复它。一切都很好。所以这可以关闭或其他。

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 2021-09-22
      • 2013-10-01
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多