OGeek|极客世界-中国程序员成长平台

标题: iphone - 如何获得有关 imageWithContentsOfFile : completion? 的通知 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 06:54
标题: iphone - 如何获得有关 imageWithContentsOfFile : completion? 的通知

我用 imageWithContentsOfFile: 加载了一个巨大的图像,所以我必须在这个过程中设置一个 activityIndi​​cator。

有没有什么方法/任何委托(delegate)回调可以用来通知这个加载过程的结束?



Best Answer-推荐答案


imageWithContentsOfFile 是同步的。

您可以启动一个事件指示器,在后台线程中将大图像加载到内存中,然后返回主线程并停止指示器。

- (void)loadBigImage {
    [activityIndicator startAnimating];
    [self performSelectorInBackgroundselector(loadBigImageInBackground) withObject:nil];
}

- (void)loadBigImageInBackground {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    UIImage *img = [UIImage imageWithContentsOfFile"..."];
    [self performSelectorOnMainThreadselector(bigImageLoaded withObject:img waitUntilDone:NO];
    [pool release];
}

- (void)bigImageLoadedUIImage *)img {
    [activityIndicator stopAnimating];
    // do stuff 
}

关于iphone - 如何获得有关 imageWithContentsOfFile : completion? 的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5379213/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4