2

使用第三方框架进行异步图像下载时性能变慢。我试过AFNetworkingand SDWebImage,滚动UICollectionView变得很慢。

我尝试了以下方法:

-(void)setImageForIndexPath:(NSIndexPath*)path withUrl:(NSURL*)url{
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFImageRequestOperation *operation;
operation = [AFImageRequestOperation imageRequestOperationWithRequest:request success:^(UIImage *image) {
    CollectionCellPreview *cell = (CollectionCellPreview *)[self.collectionView cellForItemAtIndexPath:path];
    cell.myImageView.image = image;
}];
[operation start];

}

同样:

[cell.imageLocation setImageWithURL:url];

使用这个框架我是否遗漏了一些重要的东西?它看起来非常有用和强大,我不明白为什么它会这样。

4

1 回答 1

4

在 Build -> Profile 中使用 Xcode 的 Time Profiler 查看导致延迟的原因。几乎可以肯定,在您编写的某些代码中,尽管我已经看到自动布局也会导致一些问题,尤其是在您的视图很复杂的情况下。

时间探查器教程在这里,虽然它是旧版本:http ://blancer.com/tutorials/flex/78335/apple-profiling-tools-shark-is-out-instruments-is-in/

此处自动布局性能分析:http: //pilky.me/view/36

于 2013-06-03T14:35:30.277 回答