iOS 实现动态展示LaunchScreen闪屏页

话不多说直接上代码:

在AppDelegate.m中

@interface AppDelegate ()<WXApiDelegate>
{
    UIView *launchView;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //设置rootViewController的代码
    [self configLaunchImage];
    return YES;
}
 
- (void)configLaunchImage {
    
    UIViewController *vc = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
    launchView = vc.view;
    UIWindow *mainWindow = [UIApplication sharedApplication].keyWindow;
    launchView.frame = [UIApplication sharedApplication].keyWindow.frame;
    [mainWindow addSubview:launchView];
    UIImageView *imageView=[[UIImageView alloc]init];
    [imageView sd_setImageWithURL:[NSURL URLWithString:@"http://pic15.nipic.com/20110628/1369025_192645024000_2.jpg"]];
    //根据需求添加约束最好
    imageView.frame = CGRectMake(0, 0, mainWidthWJ, mainHeightWJ);
    imageView.backgroundColor=[UIColor whiteColor];
    [launchView addSubview:imageView];
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeLaunchImage) userInfo:nil repeats:NO];
}
 
-(void)removeLaunchImage
 
{
    [launchView removeFromSuperview];
    //设置rootViewController的代码

}

接下来在LaunchScreen.storyboard设置下identifier 如图所示


屏幕快照 2019-03-28 15.11.27.png

OK大功告成!!!!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容