我下载gif图像并添加到集合视图时遇到问题.
gif图像下载得很好,但是当我尝试非常快速地滚动时它会崩溃
请帮忙.我有两个解决方案
/*
cellForGif.layer.borderColor = [[UIColor colorWithRed:54.0/255.f green:56.0/255.f blue:67.0/255.f alpha:1.0]CGColor];
cellForGif.layer.borderWidth = 0.7;
FLAnimatedImage __block *gifImage = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
gifImage = [[FLAnimatedImage alloc] initWithAnimatedGIFData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%li", (long)indexPath.row] ofType:@"gif"]]];
dispatch_async(dispatch_get_main_queue(), ^{
cellForGif.gifImage.animatedImage = gifImage;
cellForGif.linkOnGif = [self.linksArrayOnGifs objectAtIndex:indexPath.row];
//gifImage = nil;
});
});
return cellForGif;
*/
cellForGif.layer.borderColor = [[UIColor colorWithRed:54.0/255.f green:56.0/255.f blue:67.0/255.f alpha:1.0]CGColor];
cellForGif.layer.borderWidth = 0.7;
FLAnimatedImage *gifImage = nil;
gifImage = [[FLAnimatedImage alloc] initWithAnimatedGIFData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%li", (long)indexPath.row] ofType:@"gif"]]];
cellForGif.gifImage.animatedImage = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用SWITCH和GCD加载我的数组,以便不停止主线程.但Xcode无法构建我的代码.请任何人解释一下为什么我可以用这种方式使用GCD?
switch (number) {
case 0:
//case 0:exercise_name="??????";
break;
case 1:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized (self.handsMassage){
/*
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]];
_click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
self.click.delegate = self;
*/
for (int i = 1; i <= 22; i++) {
[self.arrayOfExercise addObject:(id)[UIImage imageNamed:[NSString stringWithFormat:@"ml_%i", i]].CGImage];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.playButton setHidden:NO];
});
});
break;
case 2:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized (self.loinMassage){
/*
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]];
_click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile …Run Code Online (Sandbox Code Playgroud)