YYImage
YYImage copied to clipboard
Support for `imageNamed`
As far as I can tell, there is no support for using xcasset bundles of assets with YYFrameImage
I might need some support for a project I am working on, interested in a pull request if I need it / get it done ?
YYImage project does not support xcassets because it can't access the image data in the assets and the system image cache may cause memory problems.
I recommend to use [UIImage animatedImageWithImages:duration:] to create frame image from xcassets.
You can easily prototype support in YYFrameImage by using something like:
- (nullable instancetype)initWithImageNames:(NSArray<NSString *> *)names
frameDurations:(NSArray<NSNumber *> *)frameDurations
loopCount:(NSUInteger)loopCount
{
NSString *firstName = names[0];
CGFloat scale = [UIScreen mainScreen].scale;
UIImage *firstCG = [[UIImage imageNamed:firstName] yy_imageByDecoded];
self = [self initWithCGImage:firstCG.CGImage scale:scale orientation:UIImageOrientationUp];
if (!self) return nil;
long frameByte = CGImageGetBytesPerRow(firstCG.CGImage) * CGImageGetHeight(firstCG.CGImage);
_oneFrameBytes = (NSUInteger)frameByte;
_imageNames = names.copy;
_frameDurations = frameDurations.copy;
_loopCount = loopCount;
return self;
}
And by modifying - (NSUInteger)animatedImageFrameCount and - (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index to also use _imageNames
the system image cache may cause memory problems
Could you detail how that could be an issue ?
I recommend to use [UIImage animatedImageWithImages:duration:] to create frame image from xcassets.
Which sadly doesn't support non-constant framerate :-(
YYImage only hold the image data or image file path in memory, but imageNamed method may hold the decoded image data in memory and may cause memory warning.
See also: http://stackoverflow.com/questions/22856283/use-xcassets-without-imagenamed-to-prevent-memory-problems