UIImage有可能不支持NSCoding iOS8

在UIImage的屬性中有這麼一項屬性(iOS8)編碼


@property (nonatomic, readonly) UIImageAsset *imageAsset NS_AVAILABLE_IOS(8_0); // The asset is not encoded along with the image atom

能夠看到它是不支持編碼的,若是咱們使用spa

_image = [UIImage imageNamed:@"名稱"]3d

獲得的實例_image,這種實例是有imageAsset這個屬性的code

若是不把imageAsset去掉而直接對_image進行編碼orm

 [aCoder encodeObject:_image forKey:@"image"];it


當咱們進行解碼時im

_image = [aDecoder decodeObjectForKey:@"image"];margin

會發現,獲得的_image爲nil。top


解決:

    _image = [UIImage imageNamed:@"名稱"]

對獲得的_image進行處理,

   _image = [UIImage imageWithCGImage:_image.CGImage];//這樣能去掉imageAsset屬性,不然,不支持encode

相關文章
相關標籤/搜索