【发布时间】: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.frames 和 prp.frameDur 是我从自定义属性结构中传入的值。
我遇到的问题是图像的大小在每个阶段都不同。我的源图像都是 59x47。 tImage (UIImage) 设置为 46x26(检查 size.width 和 size.height 属性)。 tFrame (UIImage) 设置为 53x35(检查相同的属性)。有谁知道为什么会发生这种情况?为什么不初始化为原始图像大小(59x47),为什么基于它们的两个UIImage对象会互不相同??
【问题讨论】:
标签: ios uiimageview uiimage png