APP启动引导页(图片/gif/视频)
在APP启动时候设置引导页,不管图片,gif,还是视频只需要一个方法
视频引导页
视频核心代码如下
URL为本地视频地址,如果为网络视频 建议预下载在本地然后下次进行播放
init(videoURL: URL, isHiddenSkipButton: Bool) {
let frame = CGRect.init(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT)
super.init(frame: frame)
self.playerController = MPMoviePlayerController.init(contentURL: videoURL)
self.playerController.view.frame = frame
self.playerController.view.alpha = 1.0
self.playerController.controlStyle = .none
self.playerController.repeatMode = .one
self.playerController.shouldAutoplay = true
self.playerController.prepareToPlay()
self.addSubview(self.playerController.view)
let movieStartButton = UIButton.init(frame: CGRect.init(x: 20, y: SCREEN_HEIGHT-70, width: SCREEN_WIDTH-40, height: 40))
movieStartButton.layer.borderWidth = 1.0
movieStartButton.layer.cornerRadius = 20
movieStartButton.layer.borderColor = UIColor.white.cgColor
movieStartButton.setTitle("开始体验", for: .normal)
movieStartButton.alpha = 0.0
movieStartButton.backgroundColor = .blue
self.playerController.view.addSubview(movieStartButton)
movieStartButton.addTarget(self, action: #selector(skipButtonClick), for: .touchUpInside)
UIView.animate(withDuration: 1.0) {
movieStartButton.alpha = 1.0
}
}
调用
let urlStr = Bundle.main.path(forResource: "第三屏.mov", ofType: nil)
let videoUrl = NSURL.fileURL(withPath: urlStr!)
let guideView = LanchHUD.init(videoURL: videoUrl, isHiddenSkipButton: false)
self.window?.rootViewController?.view.addSubview(guideView)
图片与GIF效果图如下 用了第三方库 SDWebImage
核心代码
init(imagesArray:[String],isHiddleBut:Bool) {
let frame = CGRect.init(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT)
super.init(frame: frame)
self.imageArray = imagesArray
if self.imageArray == nil || self.imageArray?.count == 0 {
return
}
self.addScrollView(frame: frame)
self.addSkipButton(isHiddenSkipButton: isHiddleBut)
self.addImages()
self.addPageControl()
}
func addImages() -> Void {
guard let imageArray = self.imageArray else {
return
}
for i in 0..<imageArray.count {
let imageView = UIImageView.init(frame: CGRect.init(x: SCREEN_WIDTH * CGFloat(i), y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
imageView.sd_setImage(with: nil, placeholderImage: UIImage.init(named: imageArray[i]), options: .avoidAutoSetImage, completed: nil)
self.pageView.addSubview(imageView)
if i == imageArray.count - 1 {
imageView.isUserInteractionEnabled = true
let startButton = UIButton.init(frame: CGRect.init(x: SCREEN_HEIGHT*0.1, y: SCREEN_HEIGHT*0.8, width: SCREEN_WIDTH*0.8, height: SCREEN_HEIGHT*0.08))
startButton.setTitle("开始体验", for: .normal)
startButton.setTitleColor(UIColor.white, for: .normal)
startButton.backgroundColor = .blue
startButton.addTarget(self, action: #selector(skipButtonClick), for: .touchUpInside)
}
}
}
```
用UISctrollView进行承载然后封装
|
请发表评论