iOS 实现动态展示LaunchScreen闪屏页

2019-03-28  本文已影响0人  神佑沽单

话不多说直接上代码:

在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大功告成!!!!

上一篇下一篇

猜你喜欢

热点阅读