【发布时间】:2011-08-11 02:39:34
【问题描述】:
我找不到简单的方法。有人帮忙吗?谢谢!
【问题讨论】:
-
你想用这些图像显示动画,或者你想同时显示它们,也许在滚动视图中?
-
谢谢你。我想同时展示它们。
标签: iphone uiimageview nsarray
我找不到简单的方法。有人帮忙吗?谢谢!
【问题讨论】:
标签: iphone uiimageview nsarray
将您的图像名称放入数组而不是图像,这样在内存方面会更好。
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
CGFloat currentOffset = 0;
for (int i = 0; i < [imageArray count]; i++) {
UIImageView *tmpImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[imageArray objectAtIndex:i]]];
currentOffset += tmpImageView.frame.size.width;
//currentOffset += tmpImageView.frame.size.height; // for vertical
tmpImageView.frame = CGRectOffset(tmpImageView.frame, currentOffset, 0);
//tmpImageView.frame = CGRectOffset(tmpImageView.frame, 0, currentOffset); // for vertical
[scrollView addSubview:tmpImageView];
[tmpImageView release];
}
scrollView.contentSize = CGSizeMake(currentOffset, scrollView.frame.size.height);
//scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, currentOffset); // for vertical
然后将该 scrollView 添加到您想要的 shichever 视图并释放它。
如您所见,这会将您的所有图像水平放置在另一个旁边。如果您想垂直执行此操作,只需取消所有注释行的注释并删除每个注释行之前的行。
【讨论】:
这就是使用 iOS4 解决此问题的方法。 iOS5 添加了一种更简单的方法来执行此操作,但您需要查看文档,因为它仍处于 NDA 之下。
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease]; imageView.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"one.png"], [UIImage imageNamed:@"two.png"], [UIImage imageNamed:@"three.png"], [UIImage imageNamed:@"four.png"], 零];【讨论】: