我在UIScrollView上显示了大量缩略图,我希望它们能够一次淡入淡出。现在,只需隐藏并显示滚动视图,它们全部加载到滚动视图后就会一起淡入。这没关系,但是可能需要很长时间才能加载500张图像。
我尝试过使用后台线程的几种不同的变体。
我认为这肯定会奏效,但没有运气。我有一个我添加到滚动视图中的所有UIImageViews的NSMutableArray,所以一旦它们全部到位并且滚动视图的大小我调用:
[self performSelectorInBackground:@selector(addThumbnailToScrollView) withObject:values];
-(void) addThumbnailToScrollView: (NSDictionary *) aDictionary {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Collection Item Count: %i, imageViewCount: %i", [self.collectionItems count],[self.imageViews count]);
UIImage *img = [Helpers getThumbnailImage:[aDictionary valueForKey:@"PhotoName"] withManufacturer:manufacturerID];
[(UIImageView*)[self.imageViews objectAtIndex:[[aDictionary valueForKey:@"i"] intValue]] setImage:img];
[(UIImageView*)[self.imageViews objectAtIndex:[[aDictionary valueForKey:@"i"] intValue]] setAlpha:0];
[UIView beginAnimations:@"fade" context:nil];
[(UIImageView*)[self.imageViews objectAtIndex:[[aDictionary valueForKey:@"i"] intValue]] setAlpha:1];
[UIView commitAnimations];
[pool drain];
}
UIView动画导致崩溃,因为在我发现对象被释放之前没有完成。即使我删除了动画位,他们的图像仍会以1对1的形式大量显示在屏幕上。
答案 0 :(得分:0)
你可以试试这个
- (无效)animateTumbs:(NSInteger的)索引{ 索引++; if([self.imageViews count]
[UIView animateWithDuration:0.2
animations:^{
[(UIImageView*)[self.imageViews objectAtIndex:[[aDictionary valueForKey:@"i"] intValue]] setAlpha:1];
}
completion:^(BOOL finished){
[self animateTumbs:index];
}];
}
或者您可以尝试:
[self performSelectorInBackground:@selector(addThumbnailToScrollView)withObject:values afterDelay:0.2];
祝你好运