【发布时间】:2010-12-21 13:07:44
【问题描述】:
我有一个滚动视图,我在主线程中添加了一些 UIButtons 和 UIActivityIndicators。 然后我执行 [NSThread detachSelectorInBackground:@selector(getImages) toTarget:self withObject:nil];
getImages 下载一些图像并将它们添加到 UIImageViews 中,然后将 UIImageViews 添加到滚动视图中,但是直到 getImages 方法完成后它们才会显示出来。 有没有办法让 scrollView 重绘或刷新或类似的东西?
与 如果我在 getImages 方法期间滚动滚动视图(用我的手指..),则会显示已添加的 UIImageViews。
- (void) getImages {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int x=5;
int y=0;
NSData *imgData;
UIImage *img;
UIImageView *imgView;
for (NSDictionary *tmp in thumbs) {
imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[Functions urlForFile:[tmp objectForKey:@"img"]]]];
if ([imgData length] > 0) {
img = [[UIImage alloc] initWithData:imgData];
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y + (133-img.size.height)/2, 100, img.size.height)];
imgView.image = img;
[imgView setAlpha:0.0];
[[self.scrollView viewWithTag:1500000*[[tmp objectForKey:@"id"] intValue]] setAlpha:1.0];
[self.scrollView addSubview:imgView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:2.0];
[[self.scrollView viewWithTag:1500000*[[tmp objectForKey:@"id"] intValue]] setAlpha:0.0];
[imgView setAlpha:1.0];
[UIView commitAnimations];
[[self.scrollView viewWithTag:1500000*[[tmp objectForKey:@"id"] intValue]] removeFromSuperview];
[imgView release];
[img release];
[imgData release];
x+=105;
if (x > 300) {
x=5;
y+=138;
}
}
}
[pool release];
[appDelegate.loadingView setHidden:YES];
}
【问题讨论】:
标签: iphone uiscrollview uiimageview redraw