问题
I want to add a short video when my app launches instead of launch image in iOS.
I have tried adding it in the viewDidAppear:
method of my initial UIViewController
, but still it shows a blank screen before it displays the video.
回答1:
You can not add a launch video instead of a launch image, but, your initial view controller can present a launch video which starts from the same image as your default (launch) image...
In any case, you should include the default (launch) image as it is displayed while the app is loading (and thus before the video is ready to be played).
回答2:
A launch image is used by iOS to show BEFORE the app is ready to respond and while viewDidLoad:
and viewWillAppear:
are called. So there is no question of INSTEAD.
I believe a launch image is a must for app submission for the App Store.
A launch image is a simple placeholder image that iOS displays when your app starts up. The launch image gives users the impression that your app is fast and responsive because it appears instantly and is quickly replaced by the first screen of your app.
Also this is something you should read:
You must provide at least one launch image. Typically, an iPhone app includes at least one launch image in portrait orientation; an iPad app includes at least one launch image in portrait orientation and at least one launch image in landscape orientation.
In general, consider reading these two pages:
Start reading from the App Launch Images section: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/App-RelatedResources/App-RelatedResources.html
回答3:
The response is a little late but with Swift 2 you can install via CocoaPods VideoSplashKit library. Then just add a little of code in your viedDidLoad
import VideoSplashKit
class ViewController: VideoSplashViewController {
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("test", ofType: "mp4")!)
self.videoFrame = view.frame
self.fillMode = .ResizeAspectFill
self.contentURL = url
}
}
Edit: You can create a method to configure when the video starts and video duration
func setupVideoBackground() {
let url = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("iphone6", ofType: "mp4")!)
self.videoFrame = view.frame
self.fillMode = .ResizeAspectFill
self.alwaysRepeat = true
self.sound = true
self.startTime = 0.0
self.duration = 100.0
self.alpha = 0.7
self.backgroundColor = UIColor.whiteColor()
self.contentURL = url
self.restartForeground = true
}
Here you can find and example with this library
来源:https://stackoverflow.com/questions/22765985/how-can-we-add-a-video-instead-of-launch-image-in-an-ios-app