1.封装一个视频播放的 UIView 在AppDelegate的didFinishLaunchingWithOptions方法中 添加到kWindow
let launchView = LaunchAnimationView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight))
kWindow.addSubview(launchView)
launchView.layer.zPosition = 10088
2.封装的View 中的代码
lazy var bgImgView: UIImageView = {
let view = UIImageView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight))
view.image = UIImage(named: "vb_start_img")
return view
}()
var timer:Timer?
override init(frame: CGRect) {
super.init(frame: frame)
config()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func config() {
addSubview(bgImgView)
Utilstool.play(name: "welcome_music",type: "caf")
let path = Bundle.main.path(forResource: "welcome_video", ofType: "mp4")
if let filePath = path {
let url = URL(fileURLWithPath: filePath)
let item = AVPlayerItem(url: url)
let player = AVPlayer(playerItem: item)
let layer = AVPlayerLayer(player: player)
layer.shouldRasterize = true
layer.rasterizationScale = UIScreen.main.scale
layer.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
layer.videoGravity = .resizeAspect
self.layer.addSublayer(layer)
player.play()
var timeCount = 0
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { t in
timeCount += 1
if timeCount >= 4 {
self.removeFromSuperview()
self.timer!.invalidate()
self.timer = nil
}
print(t)
})
}
}
记得点赞关注
|