iOS 使用storyboard 更换启动页无效问题

注:
1、加上清除启动页缓存的代码(最好是接口控制什么时候清除)
2、更换启动页时,把storyboard文件删除,重新建一个,然后把图片文件放到目录下(原图片文件删除,不要放到Assets.xcassets里)

OC

NSError *error;
    [NSFileManager.defaultManager removeItemAtPath:[NSString stringWithFormat:@"%@/Library/SplashBoard",NSHomeDirectory()] error:&error];
    if (error) {
        NSLog(@"Failed to delete launch screen cache: %@",error);
    }
复制代码

didFinishLaunchingWithOptions里调用即可
(避免每次都调用浪费资源,可本地存储bool值,通过更新接口的参数来控制bool即可)

Swift

func clearLaunchScreenCache() {
        do {
            try FileManager.default.removeItem(atPath: NSHomeDirectory()+"/Library/SplashBoard")
        } catch {
            print("Failed to delete launch screen cache: \(error)")
        }
    }
复制代码

2784338-12e9d6c26c8d00f7.png

调用时机

#pragma mark - 清除启动缓存
- (void)clearLaunchData {
    NSString *appVersion = AppVersion();
    NSString *version = [RWCacheTool userInfoCachedValueForKey:@"AppVersionForLaunch"];
    
    //未存过版本/当前版本高于存储版本则清除
    if (version && [appVersion compare:version options:NSNumericSearch] != NSOrderedDescending) {
        return;
    }
    
    [RWCacheTool userInfoCacheValue:appVersion forKey:@"AppVersionForLaunch"];
    NSError *error;
    [NSFileManager.defaultManager removeItemAtPath:[NSString stringWithFormat:@"%@/Library/SplashBoard",NSHomeDirectory()] error:&error];
    if (error) {
        NSLog(@"Failed to delete launch screen cache: %@",error);
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self clearLaunchData];
复制代码

启动页配置也可以通过设置Assets.xcassets多个不同的图片(尺寸不同、图片也可不同)来实现

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享