Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么所有异步映像加载(SDWebImage、AFNetworking)库都使用UIImageView而不是UIImage?_Ios_Objective C_Uiimageview_Afnetworking_Sdwebimage - Fatal编程技术网

Ios 为什么所有异步映像加载(SDWebImage、AFNetworking)库都使用UIImageView而不是UIImage?

Ios 为什么所有异步映像加载(SDWebImage、AFNetworking)库都使用UIImageView而不是UIImage?,ios,objective-c,uiimageview,afnetworking,sdwebimage,Ios,Objective C,Uiimageview,Afnetworking,Sdwebimage,我错过什么了吗?难道不允许它与UIImage一起使用,而不仅仅是UIImageView吗?您可以将UIImage交给其他人,并将其用于不同的用途,其中UIImageView实际上只能添加到视图中 我最初的想法是,如果你把它交给另一个类,而UIImage还没有加载,它将收到nil,并且不会传递任何新的内容。但是,如果您传递一个UIImageView,这同样适用,不是吗?AFNetworking 没错,AFNetworking类别实现(UIImageView+AFNetworking)是赤裸裸的 但

我错过什么了吗?难道不允许它与UIImage一起使用,而不仅仅是UIImageView吗?您可以将UIImage交给其他人,并将其用于不同的用途,其中UIImageView实际上只能添加到视图中

我最初的想法是,如果你把它交给另一个类,而UIImage还没有加载,它将收到
nil
,并且不会传递任何新的内容。但是,如果您传递一个UIImageView,这同样适用,不是吗?

AFNetworking 没错,AFNetworking类别实现(UIImageView+AFNetworking)是赤裸裸的

但您缺少一个功能,它可以验证和解码图像,并提供一些处理图像的选项。(在旧的AFNetworking 1.x版本中,此功能位于中。)

SDWebImage 类似地,您只看到SDWebImage的基本实现。这里有很多选项,因此我建议您查看其他一些类,但在最基本的级别上,您可以获得如下UIImage:

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:imageURL
                 options:kNilOptions
                 progress:^(NSUInteger receivedSize, NSUInteger expectedSize)
                 {
                     // update a progress view
                 }
                 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
                 {
                     if (image)
                     {
                         // Do something with the image; cacheType tells you if it was cached or not.
                     }
                 }];
异步加载 如果你把它交给另一个类,而UIImage还没有加载呢

嗯,它都是异步加载的,因此在加载UIImage之前不会调用完成块。

AFNetworking 没错,AFNetworking类别实现(UIImageView+AFNetworking)是赤裸裸的

但您缺少一个功能,它可以验证和解码图像,并提供一些处理图像的选项。(在旧的AFNetworking 1.x版本中,此功能位于中。)

SDWebImage 类似地,您只看到SDWebImage的基本实现。这里有很多选项,因此我建议您查看其他一些类,但在最基本的级别上,您可以获得如下UIImage:

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:imageURL
                 options:kNilOptions
                 progress:^(NSUInteger receivedSize, NSUInteger expectedSize)
                 {
                     // update a progress view
                 }
                 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
                 {
                     if (image)
                     {
                         // Do something with the image; cacheType tells you if it was cached or not.
                     }
                 }];
异步加载 如果你把它交给另一个类,而UIImage还没有加载呢

它都是异步加载的,所以在加载UIImage之前不会调用完成块