StartupPageView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // StartupPageView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/9/24.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyMediator
  10. class StartupPageView: UIView {
  11. /// 启动页的模型
  12. var startupModel : StartupModel?
  13. override init(frame: CGRect) {
  14. super.init(frame: frame)
  15. if isNetworkConnect {
  16. //获取启动视图
  17. let vc = UIStoryboard(name: "LaunchScreen", bundle: nil)
  18. .instantiateViewController(withIdentifier: "launch")
  19. self.addSubview(vc.view)
  20. UIApplication.shared.windows.last?.addSubview(self)
  21. configStartupApi()
  22. }
  23. }
  24. required init?(coder aDecoder: NSCoder) {
  25. fatalError("init(coder:) has not been implemented")
  26. }
  27. lazy var imageView: UIImageView = {
  28. let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight-40-83-43.5))
  29. imageView.contentMode = .scaleAspectFill
  30. imageView.clipsToBounds = true
  31. imageView.backgroundColor = UIColor.clear
  32. imageView.isUserInteractionEnabled = true
  33. imageView.addTapGesture(1, target: self, action: #selector(imageViewAction))
  34. addSubview(imageView)
  35. return imageView
  36. }()
  37. lazy var drawCircleProgressButton: DrawCircleProgressButton = {
  38. let drawCircleProgressButton = DrawCircleProgressButton(frame: CGRect(x: kScreenWidth-20-38, y: kSafeStatusBarHeight, width: 38, height: 38))
  39. drawCircleProgressButton.setTitle("跳过", for: UIControl.State.normal)
  40. drawCircleProgressButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
  41. drawCircleProgressButton.titleLabel?.font = kRegularFont12
  42. drawCircleProgressButton.trackColor = kThemeColor
  43. drawCircleProgressButton.progressColor = UIColor.white
  44. drawCircleProgressButton.fillColor = UIColor(hexString: "000000", alpha: 0.3)
  45. drawCircleProgressButton.lineWidth = 1.5
  46. drawCircleProgressButton.addTarget(self, action: #selector(skipAction), for: UIControl.Event.touchUpInside)
  47. addSubview(drawCircleProgressButton)
  48. return drawCircleProgressButton
  49. }()
  50. // 获取数据
  51. func configStartupApi() {
  52. SwiftMoyaNetWorkServiceConfig.shared().configStartupApi(completion: {
  53. [weak self] (startupModel) -> (Void) in
  54. self?.startupModel = startupModel as? StartupModel
  55. self?.imageView.kf.setImage(with: kURLImage(name: self?.startupModel?.img ?? ""), placeholder: kImage(name: "default_image"), completionHandler: { (result) in
  56. switch result {
  57. case .success(_):
  58. self?.drawCircleProgressButton.startAnimationDuration(3, with: {
  59. [weak self] in
  60. self?.skipAction()
  61. })
  62. break
  63. case .failure(_):
  64. break
  65. }
  66. })
  67. }) { [weak self] (loadingStatus) in
  68. self?.removeAnimateView()
  69. }
  70. }
  71. //跳转H5
  72. @objc func imageViewAction() {
  73. if startupModel?.url != "" {
  74. removeAnimateView()
  75. Mediator.push(H5RouterModuleType.pushWeb(URLString: startupModel?.url ?? "http://www.uptoyo.com"), animated: true)
  76. }
  77. }
  78. //跳过
  79. @objc func skipAction() {
  80. removeAnimateView()
  81. }
  82. // 移除动画
  83. func removeAnimateView() {
  84. //播放动画效果,完毕后将其移除
  85. UIView.animate(withDuration: 1, delay: 0, options: .beginFromCurrentState, animations: {
  86. [weak self] in
  87. self?.alpha = 0.0
  88. let transform = CATransform3DScale(CATransform3DIdentity, 1.5, 1.5, 1.0)
  89. self?.layer.transform = transform
  90. }) { [weak self] (finished) in
  91. self?.removeFromSuperview()
  92. }
  93. }
  94. class func startupPageView() {
  95. _ = StartupPageView.init(frame: UIScreen.main.bounds)
  96. }
  97. }