此库适用于任何希望用视频而不是无聊的静态启动图像作为启动画面的 iOS 开发者。
在您的 AppDelegate.swift 中,导入 TBVideoSplashScreen 并在 didFinishLaunchingWithOptions 中遵循下面的代码。传递给 makeAndPlayVideoSplashScreen 的启动图像是为了最佳视觉体验。获取您视频的第一帧并将其作为静态图像设置。当您的视频加载时,该启动图像将被展示给用户,给人一种视频加载略快的感觉
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
TBVideoSplashScreen.makeAndPlayVideoSplashScreen(self, videoNameString: "splashScreen", withExtension: "mp4", launchImageString: "launchScreenImage")
return true
}
确保您在本文件中实现了 @objc moviePlayBackDidFinish() 作为回调方法。这是视频播放完成时自动触发的函数。
@objc
func moviePlayBackDidFinish() {
//any custom logic for callback goes here
let vc: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewController") as! UIViewController
let navCtrl = UINavigationController(rootViewController: vc)
window?.rootViewController! = navCtrl
NSNotificationCenter.defaultCenter().removeObserver(self)
}
要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install
。
TBVideoSplashScreen 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中
pod "TBVideoSplashScreen"
Terry Bu, [email protected]
TBVideoSplashScreen 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。