显示启动画面的时间超过默认秒数

fuz*_*uzz 44 splash-screen objective-c ios

是否可以在指定的秒数内显示Default.png?我有一个客户端希望显示的启动画面的时间长于当前时间.

他们希望它显示2 - 3秒.

rck*_*nes 59

不,default.png在您的应用启动时会显示.

您可以添加一个新的viewcontroller,它将default.png在应用程序中显示didFinishLoading.

这样你可以显示default.png更长的时间.

您应该只显示default.png您是否正在加载数据,这可能需要一些时间.正如appstore指南所述,您不应该延迟启动时间超过必要时间.

  • 这样做,不要像其他答案中所建议的那样让你的应用程序进入睡眠状态.+1正确答案. (7认同)
  • 或者更好,但根本不做.它违背了HIG,就UX来说简直就是愚蠢. (3认同)

Che*_*ara 35

您还可以使用NSThread:

[NSThread sleepForTimeInterval:(NSTimeInterval)];
Run Code Online (Sandbox Code Playgroud)

您可以将此代码放入applicationDidFinishLaunching方法的第一行.

例如,显示default.png 5秒钟.

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
   [NSThread sleepForTimeInterval:5.0];
}
Run Code Online (Sandbox Code Playgroud)

  • 我的天啊!请不要使用这种方法,简直是可怕的,你正在阻止应用程序主线程冻结应用程序,正如@rckoenes所解释的那样,应用程序可以被杀死,反对任何苹果指南并且绝对是丑陋的.而是实现你的VC并显示它 (20认同)
  • 延迟启动您的应用程序可能会导致您的应用程序因加载时间过长而被看门狗杀死。所以永远不要延迟启动。 (3认同)

Dan*_*orm 20

将此添加到您的application:didFinishLaunchingWithOptions::

迅速:

// Delay 1 second
RunLoop.current.run(until: Date(timeIntervalSinceNow: 1.0))
Run Code Online (Sandbox Code Playgroud)

目标C:

// Delay 1 second
[[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow: 1.0]];
Run Code Online (Sandbox Code Playgroud)


Kap*_*ppe 9

如果您使用的是LaunchScreen.storyboard,则可以获取相同的视图控制器并显示它:(记得设置故事板ID,例如"LaunchScreen")

func applicationDidBecomeActive(application: UIApplication) {

        let storyboard = UIStoryboard(name: "LaunchScreen", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("LaunchScreen")
self.window!.rootViewController!.presentViewController(vc, animated: false, completion: nil)
        }
Run Code Online (Sandbox Code Playgroud)


Eha*_*fan 7

斯威夫特 3

通过在您指定的任何时间呈现飞溅控制器,然后将其删除并显示您的普通 rootViewController,这是可以安全的方式实现的。

  1. 首先在 LaunchingScreen.storyboard 中给你的控制器一个 StoryBoard 标识符让我们说“splashController”
  2. 在 Main.storyboard 中给你的初始 viewController 一个 StoryBoard 标识符让我们说“initController”。- 这可能是导航或标签栏等...-

在 AppDelegate 中,您可以创建以下 2 个方法:

  1. private func extendSplashScreenPresentation(){
        // Get a refernce to LaunchScreen.storyboard
        let launchStoryBoard = UIStoryboard.init(name: "LaunchScreen", bundle: nil)
        // Get the splash screen controller
        let splashController = launchStoryBoard.instantiateViewController(withIdentifier: "splashController")
        // Assign it to rootViewController
        self.window?.rootViewController = splashController
        self.window?.makeKeyAndVisible()
        // Setup a timer to remove it after n seconds
        Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(dismissSplashController), userInfo: nil, repeats: false)
    }
    
    Run Code Online (Sandbox Code Playgroud)

2.

@objc private func dismissSplashController() {
    // Get a refernce to Main.storyboard
    let mainStoryBoard = UIStoryboard.init(name: "Main", bundle: nil)
    // Get initial viewController
    let initController = mainStoryBoard.instantiateViewController(withIdentifier: "initController")
    // Assign it to rootViewController
    self.window?.rootViewController = initController
    self.window?.makeKeyAndVisible()
}
Run Code Online (Sandbox Code Playgroud)

现在你打电话

 self.extendSplashScreenPresentation()
Run Code Online (Sandbox Code Playgroud)

在 didFinishLaunchingWithOptions 中。

你准备去...


vis*_*kh7 5

教程显示启动画面2秒钟.您可以轻松更改它以满足您的需求.

- (void)showSplash {
  UIViewController *modalViewController = [[UIViewController alloc] init];
  modalViewController.view = modelView;
  [self presentModalViewController:modalViewController animated:NO];
  [self performSelector:@selector(hideSplash) withObject:nil afterDelay:yourDelay];
}
Run Code Online (Sandbox Code Playgroud)


Him*_*jan 5

didFinishLaunchingWithOptions:委托方法中使用以下行:

[NSThread sleepForTimeInterval:5.0];
Run Code Online (Sandbox Code Playgroud)

它将停止启动屏幕5.0秒.

  • 延迟启动您的应用程序可能会导致您的应用程序被监视程序杀死以便长时间加载.所以永远不要拖延启动. (11认同)

Mr.*_*ddy 5

在Xcode 6.1中,Swift 1.0可以延迟启动屏幕:

将此添加到 didFinishLaunchingWithOptions

NSThread.sleepForTimeInterval(3)
Run Code Online (Sandbox Code Playgroud)

()中的时间是可变的。

迅速发展

Thread.sleep(forTimeInterval:3)
Run Code Online (Sandbox Code Playgroud)


MB_*_*per 5

这在Xcode 6.3.2,Swift 1.2中对我有用:

import UIKit

class ViewController: UIViewController
{
    var splashScreen:UIImageView!

    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.splashScreen = UIImageView(frame: self.view.frame)
        self.splashScreen.image = UIImage(named: "Default.png")
        self.view.addSubview(self.splashScreen)

        var removeSplashScreen = NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: "removeSP", userInfo: nil, repeats: false)
    }

    func removeSP()
    {
        println(" REMOVE SP")
        self.splashScreen.removeFromSuperview()
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
    }
}
Run Code Online (Sandbox Code Playgroud)

ViewController是第一个正在加载的应用VC.


小智 5

在斯威夫特 4.2 中

默认启动时间后延迟 1 秒...

Thread.sleep(forTimeInterval: 1)
Run Code Online (Sandbox Code Playgroud)