Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets只能通过imagedNamed? #5

Open
TurboPPeng opened this issue May 26, 2016 · 7 comments
Open

Assets只能通过imagedNamed? #5

TurboPPeng opened this issue May 26, 2016 · 7 comments

Comments

@TurboPPeng
Copy link

现在Assets里面的图片不是可以通过imageWithContentsOfFile的方式获取的么?怎么看你前面说不可以的?

@Magic-Unique
Copy link
Owner

愿闻其详

@TurboPPeng
Copy link
Author

类似这样
NSString *path = [[NSBundle mainBundle] pathForResource:@"startView" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
我直接读的启动图,启动图在Assets里面,是可以读到的呀

@Magic-Unique
Copy link
Owner

你把最低系统改为9.0。然后获取的path就是nil了

@TurboPPeng
Copy link
Author

这个是9.0之后的事情?我一直停留在最低7.0,运行在9.0上,正常的。难道只要吧最低版本降到9.0就可以使用?

@Magic-Unique
Copy link
Owner

低版本的iOS系统不支持解包Assets文件,所以Xcode监测到到你需要支持低版本的iOS时候,会在打包ipa的时候把Assets里的图片全部拷贝一份到根目录下,所以你可以用ContentsOfFile读到图片

@TurboPPeng
Copy link
Author

我刚测试了一下,如果是jpg文件,不会被打包到.car文件中,可以用ContentsOfFile读取到,打包的就不可以读取了

@Magic-Unique
Copy link
Owner

所以能读取的情况有条件限制, 而Apple本身就是希望Assets.car文件是无法解包的(我查了一下Apple是用CoreUI.framework解析car文件的), 这样在平时开发中, 就只能用imageNamed:来读取car中的图片了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants