search

Home  >  Q&A  >  body text

swift - iOS启动页面之后会黑屏1秒左右才进入主画面

我的app启动页面是用的图片,如下图。

但是每次启动的时候,启动图片结束后会黑屏1秒左右才进入主页面,这是为什么呢?
而且奇怪的是,并不是次次都黑屏,有时候又不黑屏。

大家讲道理大家讲道理2773 days ago739

reply all(9)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:15:32

    I found the reason. When the loaded home page is initialized, there is a data reading operation that is performed synchronously, which will block the UI thread and cause the UI to briefly black screen. Just change it to asynchronous.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:15:32

    I suspect it took too long.

    You can print the timestamp on the didFinishLaunchingWithOptions first line of appDelegate and the timestamp of viewDidAppear on the home page to see if the difference between the two is too long. Are there any time-consuming operations on the main thread, such as reading and writing databases, loading large files, etc.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:15:32

    Occasional bugs are more difficult to deal with. Did the ViewController of the first interface do anything to block the main thread before ViewAppear?
    If not, you can first try assigning LaunchScreen to a StoryBoard file and then fill the LaunchScreen with pictures.

    reply
    0
  • PHPz

    PHPz2017-04-18 09:15:32

    Is the rootViewController of your window set?

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:15:32

    The black screen means that your rootVC interface is not displayed, or it is black or empty. It is recommended to set the view of rootVC to an eye-catching color, such as red, and check the situation

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:15:32

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = XXX;
    [self.window makeKeyAndVisible];

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:15:32

    Is it that the startup page corresponding to the device screen size has not been added

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:15:32

    The startup page is not loaded, don’t use lanuchimage, create a StoryBoard and spread the pictures on it, it will be ok

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:15:32

    I also have the same problem. The LaunchImage shows that when the program is re-awakened, the page comes out and the screen flashes black.

    reply
    0
  • Cancelreply