iPhone:从Documents文件夹中显示启动画面

nit*_*hin 3 iphone splash-screen objective-c ios

在我的应用程序中,我需要显示一个启动画面.我从URL收集图像并将其保存Default.png在文档文件夹中.

我成功保存了图像并收集了路径.

我的问题是它没有显示.我没有得到任何错误,在日志中我也得到了正确的路径.

这是我的代码:

 NSString *workSpacePath=[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"/Default.png"];
    imgView=[[UIImageView alloc] init];
    imgView.image=[UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]];    

    [self.view addSubview:imgView];
Run Code Online (Sandbox Code Playgroud)

我有正确的道路workSpacePath.

Mat*_*uch 6

请勿使用该[UIImage imageNamed:]方法覆盖您的图像.此方法仅适用于作为捆绑包一部分的图像.对于文档目录中的路径,它将返回nil.因此,你设置imgView.image为零.这意味着,删除图像.

这应该工作:

NSString *workSpacePath=[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Default.png"];
imgView=[[UIImageView alloc] init];
imgView.image=[UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]];    
//imgView.image=[UIImage imageNamed:workSpacePath];
[self.view addSubview:imgView];
Run Code Online (Sandbox Code Playgroud)

但你不能取代"真正的"闪屏.但是,在原始闪屏消失后,您可以显示不同的图像.