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指南所述,您不应该延迟启动时间超过必要时间.
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)
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)
如果您使用的是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)
斯威夫特 3
通过在您指定的任何时间呈现飞溅控制器,然后将其删除并显示您的普通 rootViewController,这是可以安全的方式实现的。
在 AppDelegate 中,您可以创建以下 2 个方法:
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 中。
你准备去...
本教程显示启动画面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)
在didFinishLaunchingWithOptions:委托方法中使用以下行:
[NSThread sleepForTimeInterval:5.0];
Run Code Online (Sandbox Code Playgroud)
它将停止启动屏幕5.0秒.
在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)
这在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)
| 归档时间: |
|
| 查看次数: |
98585 次 |
| 最近记录: |