| | |
| | | // |
| | | // GamesIntruduceView.swift |
| | | // WanPai |
| | | // |
| | | // Created by 无故事王国 on 2023/9/15. |
| | | // |
| | | // |
| | | // GamesIntruduceView.swift |
| | | // WanPai |
| | | // |
| | | // Created by 无故事王国 on 2023/9/15. |
| | | // |
| | | |
| | | import UIKit |
| | | import JQTools |
| | | import AVKit |
| | | |
| | | class GamesIntruduceView: UIView,JQNibView{ |
| | | |
| | | @IBOutlet weak var img_profile: UIImageView! |
| | | @IBOutlet weak var label_content: UILabel! |
| | | @IBOutlet weak var view_container: UIView! |
| | | |
| | | @IBOutlet weak var btn_play: UIButton! |
| | | |
| | | private var videoUrl:String? |
| | | |
| | | override func awakeFromNib() { |
| | | super.awakeFromNib() |
| | | view_container.transform = CGAffineTransform(scaleX: 0.1, y: 0.1) |
| | |
| | | layoutIfNeeded() |
| | | } |
| | | |
| | | static func show(){ |
| | | static func show(url:String,content:String){ |
| | | let intruduceView = GamesIntruduceView.jq_loadNibView() |
| | | intruduceView.frame = sceneDelegate?.window?.frame ?? .zero |
| | | sceneDelegate?.window?.addSubview(intruduceView) |
| | | intruduceView.label_content.text = content |
| | | |
| | | UIView.animate(withDuration: 0.5) { |
| | | intruduceView.alpha = 1 |
| | | intruduceView.view_container.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) |
| | | } completion: { _ in |
| | | if url.lowercased().contains("jpg") || url.lowercased().contains("png") || url.lowercased().contains("jpeg"){ |
| | | intruduceView.img_profile.sd_setImage(with: URL(string: url)) |
| | | intruduceView.btn_play.isHidden = true |
| | | }else{ |
| | | intruduceView.btn_play.isHidden = false |
| | | intruduceView.videoUrl = url |
| | | guard !url.isEmpty else {return} |
| | | guard let Url = URL(string: url) else { return } |
| | | DispatchQueue.global(qos: .utility).async { |
| | | do { |
| | | let asset = AVURLAsset.init(url: Url) |
| | | let gen = AVAssetImageGenerator.init(asset: asset) |
| | | gen.appliesPreferredTrackTransform = true |
| | | let time = CMTimeMakeWithSeconds(0.0, preferredTimescale: 1) |
| | | var actualTime : CMTime = CMTimeMakeWithSeconds(0, preferredTimescale: 0) |
| | | let image = try gen.copyCGImage(at: time, actualTime: &actualTime) |
| | | |
| | | DispatchQueue.main.async { |
| | | intruduceView.img_profile.image = UIImage.init(cgImage: image) |
| | | } |
| | | } catch { |
| | | print("错误") |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | UIView.animate(withDuration: 0.5) { |
| | | intruduceView.alpha = 1 |
| | | intruduceView.view_container.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) |
| | | } completion: { _ in |
| | | |
| | | @IBAction func closeAction(_ sender: UIButton) { |
| | | UIView.animate(withDuration: 0.5) { |
| | | self.alpha = 0 |
| | | self.view_container.transform = CGAffineTransform(scaleX: 0.1, y: 0.1) |
| | | } completion: { _ in |
| | | self.removeFromSuperview() |
| | | } |
| | | } |
| | | |
| | | @IBAction func playAction(_ sender: UIButton) { |
| | | let playerVC = AVPlayerViewController() |
| | | playerVC.allowsPictureInPicturePlayback = false |
| | | playerVC.player = AVPlayer(url: URL(string: videoUrl)!) |
| | | playerVC.player?.play() |
| | | |
| | | JQ_currentViewController().present(playerVC, animated: true) |
| | | } |
| | | |
| | | @IBAction func closeAction(_ sender: UIButton) { |
| | | UIView.animate(withDuration: 0.5) { |
| | | self.alpha = 0 |
| | | self.view_container.transform = CGAffineTransform(scaleX: 0.1, y: 0.1) |
| | | } completion: { _ in |
| | | self.removeFromSuperview() |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |