QSLGuideController.swift 5.7 KB

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