美文网首页
iOS 实现动态展示LaunchScreen闪屏页

iOS 实现动态展示LaunchScreen闪屏页

作者: 神佑沽单 | 来源:发表于2019-03-28 15:13 被阅读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大功告成!!!!

    相关文章

      网友评论

          本文标题:iOS 实现动态展示LaunchScreen闪屏页

          本文链接:https://www.haomeiwen.com/subject/pfwqbqtx.html