QSLGuideController.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // QSLGuideController.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/12/9.
  6. //
  7. import UIKit
  8. import GKCycleScrollView
  9. class QSLGuideController: QSLBaseController {
  10. // var currentPage
  11. lazy var cycleScrollView: GKCycleScrollView = {
  12. let cycleScrollView = GKCycleScrollView()
  13. cycleScrollView.dataSource = self
  14. cycleScrollView.delegate = self
  15. cycleScrollView.isAutoScroll = false
  16. cycleScrollView.isInfiniteLoop = false
  17. cycleScrollView.isChangeAlpha = false
  18. cycleScrollView.pageControl = pageControl
  19. return cycleScrollView
  20. }()
  21. lazy var pageControl: GKPageControl = {
  22. let pageControl = GKPageControl()
  23. pageControl.style = .rectangle
  24. pageControl.dotHeight = 4.rpx
  25. pageControl.dotWidth = 20.rpx
  26. pageControl.dotMargin = 4.rpx
  27. pageControl.pageIndicatorTintColor = .hexStringColor(hexString: "#EEEEEE")
  28. pageControl.currentPageIndicatorTintColor = QSLColor.themeMainColor
  29. return pageControl
  30. }()
  31. lazy var nextButton: UIButton = {
  32. let btn = UIButton()
  33. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 280.rpx, height: 44.rpx, direction: .horizontal)
  34. btn.title("下一步")
  35. btn.mediumFont(16)
  36. btn.textColor(.white)
  37. btn.addRadius(radius: 22.rpx)
  38. btn.addTarget(self, action: #selector(nextBtnAction), for: .touchUpInside)
  39. return btn
  40. }()
  41. override func viewDidLoad() {
  42. super.viewDidLoad()
  43. self.view.addSubview(cycleScrollView)
  44. cycleScrollView.snp.makeConstraints { make in
  45. make.left.equalTo(40.rpx)
  46. make.right.equalTo(-40.rpx)
  47. make.height.equalTo(368.rpx)
  48. make.top.equalTo(QSLConst.qsl_kStatusBarFrameH + 72.rpx)
  49. }
  50. self.view.addSubview(pageControl)
  51. pageControl.snp.makeConstraints { make in
  52. make.size.equalTo(CGSize(width: 68.rpx, height: 4.rpx))
  53. make.centerX.equalToSuperview()
  54. make.top.equalTo(cycleScrollView.snp.bottom).offset(17.rpx)
  55. }
  56. self.view.addSubview(nextButton)
  57. nextButton.snp.makeConstraints { make in
  58. make.size.equalTo(CGSize(width: 280.rpx, height: 44.rpx))
  59. make.centerX.equalToSuperview()
  60. make.top.equalTo(pageControl.snp.bottom).offset(50.rpx)
  61. }
  62. cycleScrollView.reloadData()
  63. }
  64. // 点击下一步按钮
  65. @objc func nextBtnAction() {
  66. switch cycleScrollView.currentSelectIndex {
  67. case 0:
  68. gravityInstance?.track(QSLGravityConst.guide_first_click)
  69. break
  70. case 1:
  71. gravityInstance?.track(QSLGravityConst.guide_second_click)
  72. break
  73. case 2:
  74. gravityInstance?.track(QSLGravityConst.guide_third_click)
  75. break
  76. default:
  77. break
  78. }
  79. if cycleScrollView.currentSelectIndex == 2 {
  80. if let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate {
  81. sceneDelegate.window?.rootViewController = CustomTabBarController()
  82. sceneDelegate.window?.makeKeyAndVisible()
  83. }
  84. } else {
  85. cycleScrollView.scrollToCell(at: cycleScrollView.currentSelectIndex + 1, animated: true)
  86. }
  87. }
  88. }
  89. extension QSLGuideController: GKCycleScrollViewDataSource, GKCycleScrollViewDelegate {
  90. func numberOfCells(in cycleScrollView: GKCycleScrollView!) -> Int {
  91. return 3
  92. }
  93. func cycleScrollView(_ cycleScrollView: GKCycleScrollView!, cellForViewAt index: Int) -> GKCycleScrollViewCell! {
  94. if let cell = cycleScrollView.dequeueReusableCell() {
  95. cell.imageView.image = UIImage(named: "guide_pic_\(index + 1)")
  96. return cell
  97. }
  98. let cell = GKCycleScrollViewCell()
  99. cell.imageView.image = UIImage(named: "guide_pic_\(index + 1)")
  100. return cell
  101. }
  102. func cycleScrollView(_ cycleScrollView: GKCycleScrollView!, didScrollCellTo index: Int) {
  103. switch index {
  104. case 0:
  105. gravityInstance?.track(QSLGravityConst.guide_first_show)
  106. break
  107. case 1:
  108. gravityInstance?.track(QSLGravityConst.guide_second_show)
  109. break
  110. case 2:
  111. gravityInstance?.track(QSLGravityConst.guide_third_show)
  112. break
  113. default:
  114. break
  115. }
  116. }
  117. }