如何更换当前的启动图像?

时间:2014-11-11 10:39:38

标签: ios objective-c xcode

我想在我启动应用程序时下载图像并将其存储在本地,下次运行应用程序时,我可以使用该图像替换当前的启动图像吗?

如何做到这一点?谢谢

3 个答案:

答案 0 :(得分:1)

你不能这样做。启动图像并非动态,除非它响应设备方向。

有关启动图片的更多信息:https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/LaunchImages.html

您可以做的最好的事情是,在应用启动时,使用从您的启动图片到您已下载的自定义图片的某种良好过渡。

答案 1 :(得分:0)

您不能在image.xcassets中使用默认的LaunchScreen.xib LaunchImage,因为两种方式都没有代码执行。

上次,我通过使用将呈现实际ViewController的中间ViewController来完成它。

因此,中间ViewController将具有类似的构造函数:

-(instancetype)initWithMainViewController:(ViewController*)vc;

然后在viewDidLoad

-(void)viewDidLoad;
{
    [super viewDidLoad];

_imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
// assuming your downloaded image will always be stored in Documents/dynamicDefaultImage.png
NSString* downloadedImagePath =     [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"dynamicDefaultImage.png"];
    if ( [[NSFileManager defaultManager] fileExistsAtPath:downloadedImagePath] ) {
        [_imageView setImage:[UIImage imageWithContentsOfFile:downloadedImagePath]];
    } else {
    // prepare built in image in case your download failed.
        [_imageView setImage:[UIImage imageNamed:@"builtInLaunchImage"]];
    }

    // present the actual VC after certain delay
    [self performSelector:@selector(loadActualVc) withObject:nil afterDelay:1.0];
}

- (void)loadActualVc;
{
    [self presentViewController:_mainViewController animated:YES completion:^{
        // clear the image so that this VC will just be empty VC once main view controller is presented.
        [_imageView setImage:nil];
    }];
}

与在AppDelegate完成启动之前调用的默认LaunchImage相比,加载所需的时间非常短。此外,一旦呈现实际的视图控制器,当图像被卸载时,存储器消耗也将保持最小。如果您确实每周/每月更新着陆页,我认为这是值得的。

答案 2 :(得分:-1)

是的,你可以改变你的LunchImage

只需转到Images.xcassets文件夹,有两个选项AppIconLaunchImage,点击LaunchImage,拖放您想要的图片。

注意: - 请注意您放下的图像的大小,否则会出现The app icon set named "AppIcon" did not have any applicable content之类的错误。

相关问题