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

是否有可能显示Default.png指定的秒数? 我有一个客户端,希望显示的启animation面比当前时间更长。

他们希望显示2 – 3秒。

不,应用程序启动时会显示default.png

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

这样你显示default.png有点长。

如果您正在加载数据,则只应显示default.png ,这可能需要一些时间。 正如AppStore的指导方针所述,你不应该拖延开始你的任何时间。

你也可以使用NSThread

 [NSThread sleepForTimeInterval:(NSTimeInterval)]; 

你可以把这段代码放到applicationDidFinishLaunching方法的第一行。

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

 - (void) applicationDidFinishLaunching:(UIApplication*)application { [NSThread sleepForTimeInterval:5.0]; } 

本教程显示启动屏幕2秒钟。 您可以轻松地更改以适应您的需求。

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

这在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() } } 

ViewController是第一个正在加载的应用程序VC。

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

 [NSThread sleepForTimeInterval:5.0]; 

它将停止闪屏5.0秒。

如果您使用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) } 

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

将此添加到didFinishLaunchingWithOptions

 NSThread.sleepForTimeInterval(3) 

()中的时间是可变的。

你可以使用下面的代码:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSMutableString *path = [[NSMutableString alloc]init]; [path setString:[[NSBundle mainBundle] resourcePath]]; [path setString:[path stringByAppendingPathComponent:@"Default.png"]]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]; [path release]; UIImageView *imageView=[[UIImageView alloc]initWithImage:image]; imageView.frame=CGRectMake(0, 0, 320, 480); imageView.tag = 2; [window addSubview:imageView]; [window makeKeyAndVisible]; // Here specify the time limit. timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(timerForLoadingScreen) userInfo:nil repeats:YES]; } -(void)timerForLoadingScreen { [timer invalidate]; if ([window viewWithTag:2]!=nil) { [[window viewWithTag:2]removeFromSuperview]; } // Your any other initialization code that you wish to have in didFinishLaunchingWithOptions } 

Swift 2.0:

1)

 // AppDelegate.swift import UIKit import Foundation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var splashTimer:NSTimer? var splashImageView:UIImageView? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { window = UIApplication.sharedApplication().delegate!.window! let splashImage: UIImage = UIImage(named: "ic_120x120.png")! splashImageView = UIImageView(image: splashImage) splashImageView!.frame = CGRectMake(0, 0, (window?.frame.width)!, (window?.frame.height)!) window!.addSubview(splashImageView!) window!.makeKeyAndVisible() //Adding splash Image as UIWindow's subview. window!.bringSubviewToFront(window!.subviews[0]) // Here specify the timer. splashTimer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "splashTimerForLoadingScreen", userInfo: nil, repeats: true) return true } func splashTimerForLoadingScreen() { splashImageView!.removeFromSuperview() splashTimer!.invalidate() } 

2)

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { NSThread.sleepForTimeInterval(9) OR sleep(9) return true } 

3)使用根视图控制器概念:

 // AppDelegate.swift import UIKit import Foundation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var splashTimer:NSTimer? var storyboard:UIStoryboard? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { window = UIWindow(frame: UIScreen.mainScreen().bounds) window?.makeKeyAndVisible() storyboard = UIStoryboard(name: "Main", bundle: nil) //Here set the splashScreen VC let rootController = storyboard!.instantiateViewControllerWithIdentifier("secondVCID") if let window = self.window { window.rootViewController = rootController } //Set Timer splashTimer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "splashTimerCrossedTimeLimit", userInfo: nil, repeats: true) return true } func splashTimerCrossedTimeLimit(){ //Here change the root controller let rootController = storyboard!.instantiateViewControllerWithIdentifier("firstVCID") if let window = self.window { window.rootViewController = rootController } splashTimer?.invalidate() } 

添加到您的application:didFinishLaunchingWithOptions: ::

迅速:

 // Delay 1 second NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 1)) 

目标C:

 // Delay 1 second [[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow: 1]]; 

把你的default.png放在UIImageView的全屏幕中,作为主视图顶部的子视图,覆盖你的其他用户界面。 设置一个计时器,在x秒后将其删除(可能带有效果),现在显示您的应用程序。

实现这个最简单的方法是在第一个ViewController的UIView的顶部创build一个带有“Default.png”的UIImageView

并添加一个定时器,以预期的秒后,删除UIImageView

sleep(5.0)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 5秒启animation面将被显示

这工作…

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Load Splash View Controller first self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Splash"]; self.window.rootViewController = viewController; [self.window makeKeyAndVisible]; // Load other stuff that requires time // Now load the main View Controller that you want } 

1.在“didFinishLaunchingWithOptions”中添加另一个视图控制器

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UINavigationController *homeNav = [storyboard instantiateViewControllerWithIdentifier:@"NavigationControllerView"]; UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"SplashViewController"]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = homeNav; [self.window makeKeyAndVisible]; [(UINavigationController *)self.window.rootViewController pushViewController:viewController animated:NO]; } 

2.鉴于SplashView控制器的负载

  [self performSelector:@selector(removeSplashScreenAddViewController) withObject:nil afterDelay:2.0]; 

3.在removeSplashScreenAddViewController方法中,你可以添加你的主视图控制器eg.-

 - (void) removeSplashScreenAddViewController {` UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UINavigationController *homeNav = [storyboard instantiateViewControllerWithIdentifier:@"HomeNav"]; UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:viewControllerName]; UIWindow *window = [StaticHelper mainWindow]; window.rootViewController = homeNav; [window makeKeyAndVisible]; [(UINavigationController *)window.rootViewController pushViewController:viewController animated:NO];`} 

只要去项目名称。 然后右键单击/属性/应用程序选项卡。 在斜杠窗体combobox中查找“查看应用程序事件”。 在myApplication类中复制这段代码:

  Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup System.Threading.Thread.Sleep(3000) ' or other time End Sub 

您可以创build自己的视图并在应用程序启动时显示它,并用计时器隐藏它。 请避免延迟应用程序启动,因为它的坏主意

您可以简单地指定在AppDelegate didFinishLaunchingWithOptions方法中睡眠的秒数。

或者也可以使用其他ImageView来自定义启animation面。

在我的以下链接中查看后者的细节:

初始屏幕问题