iOS: 如何延迟启动画面?
iOS: how to delay the launch screen?
启动应用程序时,LaunchScreen.xib会在所有资产初始化后立即删除。
我想让启动画面至少停留 1 秒
有办法实现吗?
谢谢!
您可以创建一个使用 LaunchScreen 情节提要的视图控制器,在 applicationDidFinishLaunching
或 applicationWillFinishLaunching
上展示它(不是动画),然后在需要时关闭它。
请记住,Apple 不鼓励这样做,因为它给人的印象是您的应用需要很长时间才能启动,这是糟糕的用户体验,可能会导致您的一些用户删除您的应用。
如果你想用简单的,你可以使用NSThread
:
[NSThread sleepForTimeInterval:(NSTimeInterval)];
你可以把这段代码放在applicationDidFinishLaunching
方法的第一行。
例如显示default.png1.0秒
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[NSThread sleepForTimeInterval:1.0];
}
它将停止启动画面 1.0 秒。
以为我对此发表了自己的看法,我想写评论,但不允许多行。我相信许多应用程序开发人员想要这样做(延迟启动屏幕)是因为他们想为他们的公司建立 apps/games 的品牌影响力。
话虽如此,启动屏幕并不是为此而设计的,正如 Rick Maddy 在其他答案之一的评论部分中所解释的那样。启动屏幕的目的是通过在后面加载实际数据(willAppear 等)时显示空白 UI 让用户感觉应用程序立即 运行。
所以要实现许多开发者想要的,同时与 Apple 的 HIG 保持一致,您可以做的是:
- Display UI template in the launchscreen as intended by Apple HIG.
- Upon main screen load, load up another VC that shows "intro" of your brand. Make sure this runs only ONCE (a simple flag in
NSUserDefaults should do the trick).
- Users should be allowed to skip this if it is a long "intro".
相同的 "intro" VC 应该可以通过点击某个地方的 "View Intro" 按钮(可能在关于页面)供用户使用。
从不 在主线程上休眠。这样做实际上可能会导致 iOS 因启动时间过长而终止您的应用程序
Swift 4 次更新
只需写一行代码
Thread.sleep(forTimeInterval: 3.0)
在didfinishLauching....
的方法在appdelegate
class.
例子
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Thread.sleep(forTimeInterval: 3.0)
// Override point for customization after application launch.
return true
}
Alhamdulellah 解决方案是找到
只复制粘贴这段代码到 AppDelegate Class
在 didFinishLaunchingWithOptions()
中调用这个 SplashScreenTiming()
private func SplashScreenTiming(){
let LunchScreenVC = UIStoryboard.init(name: "LaunchScreen", bundle: nil)
let rootVc = LunchScreenVC.instantiateViewController(withIdentifier: "splashController")
self.window?.rootViewController = rootVc
self.window?.makeKeyAndVisible()
Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(DismissSpalshController), userInfo: nil, repeats: false)
}
@objc func DismissSpalshController(){
let mainVC = UIStoryboard.init(name: "Main", bundle: nil)
let rootvc = mainVC.instantiateViewController(withIdentifier: "SignInVC")
self.window?.rootViewController = rootvc
self.window?.makeKeyAndVisible()
}
启动应用程序时,LaunchScreen.xib会在所有资产初始化后立即删除。
我想让启动画面至少停留 1 秒
有办法实现吗?
谢谢!
您可以创建一个使用 LaunchScreen 情节提要的视图控制器,在 applicationDidFinishLaunching
或 applicationWillFinishLaunching
上展示它(不是动画),然后在需要时关闭它。
请记住,Apple 不鼓励这样做,因为它给人的印象是您的应用需要很长时间才能启动,这是糟糕的用户体验,可能会导致您的一些用户删除您的应用。
如果你想用简单的,你可以使用NSThread
:
[NSThread sleepForTimeInterval:(NSTimeInterval)];
你可以把这段代码放在applicationDidFinishLaunching
方法的第一行。
例如显示default.png1.0秒
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[NSThread sleepForTimeInterval:1.0];
}
它将停止启动画面 1.0 秒。
以为我对此发表了自己的看法,我想写评论,但不允许多行。我相信许多应用程序开发人员想要这样做(延迟启动屏幕)是因为他们想为他们的公司建立 apps/games 的品牌影响力。
话虽如此,启动屏幕并不是为此而设计的,正如 Rick Maddy 在其他答案之一的评论部分中所解释的那样。启动屏幕的目的是通过在后面加载实际数据(willAppear 等)时显示空白 UI 让用户感觉应用程序立即 运行。
所以要实现许多开发者想要的,同时与 Apple 的 HIG 保持一致,您可以做的是:
- Display UI template in the launchscreen as intended by Apple HIG.
- Upon main screen load, load up another VC that shows "intro" of your brand. Make sure this runs only ONCE (a simple flag in NSUserDefaults should do the trick).
- Users should be allowed to skip this if it is a long "intro".
相同的 "intro" VC 应该可以通过点击某个地方的 "View Intro" 按钮(可能在关于页面)供用户使用。
从不 在主线程上休眠。这样做实际上可能会导致 iOS 因启动时间过长而终止您的应用程序
Swift 4 次更新
只需写一行代码
Thread.sleep(forTimeInterval: 3.0)
在didfinishLauching....
的方法在appdelegate
class.
例子
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Thread.sleep(forTimeInterval: 3.0)
// Override point for customization after application launch.
return true
}
Alhamdulellah 解决方案是找到
只复制粘贴这段代码到 AppDelegate Class
在 didFinishLaunchingWithOptions()
private func SplashScreenTiming(){
let LunchScreenVC = UIStoryboard.init(name: "LaunchScreen", bundle: nil)
let rootVc = LunchScreenVC.instantiateViewController(withIdentifier: "splashController")
self.window?.rootViewController = rootVc
self.window?.makeKeyAndVisible()
Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(DismissSpalshController), userInfo: nil, repeats: false)
}
@objc func DismissSpalshController(){
let mainVC = UIStoryboard.init(name: "Main", bundle: nil)
let rootvc = mainVC.instantiateViewController(withIdentifier: "SignInVC")
self.window?.rootViewController = rootvc
self.window?.makeKeyAndVisible()
}