OOGuidePageController.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // OOGuidePageController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2018/4/5.
  6. // Copyright © 2018年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. class OOGuidePageController: UIViewController,UIScrollViewDelegate {
  11. @IBOutlet weak var containerView: UIScrollView!
  12. @IBOutlet weak var pageControl: UIPageControl!
  13. @IBOutlet weak var startButton: OOBaseUIButton!
  14. private var pageImageNames:[String] = ["引导页-1","引导页-2","引导页-3","引导页-4","引导页-5"]
  15. override func awakeFromNib() {
  16. //设置button
  17. }
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. title = "引导页"
  21. initPage()
  22. }
  23. private func initPage(){
  24. //容器
  25. self.containerView.contentSize = imagesContentSize()
  26. self.containerView.isDirectionalLockEnabled = true
  27. self.containerView.delegate = self
  28. self.containerView.isPagingEnabled = true
  29. self.containerView.showsHorizontalScrollIndicator = false
  30. imageViews().forEach { (imageView) in
  31. self.containerView.addSubview(imageView)
  32. }
  33. self.pageControl.numberOfPages = pageImageNames.count
  34. self.pageControl.currentPage = 0
  35. }
  36. @objc private func buttonClicked(_ sender:Any?){
  37. let url = URL(string:UIApplication.openSettingsURLString)!
  38. UIApplication.shared.openURL(url)
  39. }
  40. private func imagesContentSize() -> CGSize {
  41. let sHeight = SCREEN_WIDTH
  42. let sWidth = SCREEN_WIDTH * CGFloat(pageImageNames.count)
  43. return CGSize(width: sWidth, height: sHeight)
  44. }
  45. // MARK:- 返回图片页视图列表
  46. private func imageViews() -> [UIView] {
  47. var views:[UIView] = []
  48. for index in 0..<pageImageNames.count {
  49. let imageView = UIImageView(image: UIImage(named: pageImageNames[index]))
  50. imageView.frame = CGRect(x: (SCREEN_WIDTH * CGFloat(index)), y: 0, width: SCREEN_WIDTH
  51. , height: SCREEN_HEIGHT)
  52. views.append(imageView)
  53. }
  54. return views
  55. }
  56. override func didReceiveMemoryWarning() {
  57. super.didReceiveMemoryWarning()
  58. // Dispose of any resources that can be recreated.
  59. }
  60. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  61. //OOLog(scrollView.contentOffset)
  62. let currentPage = scrollView.contentOffset.x / scrollView.frame.size.width
  63. pageControl.currentPage = Int(currentPage)
  64. if pageControl.currentPage + 1 == pageControl.numberOfPages {
  65. pageControl.isHidden = true
  66. UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .allowAnimatedContent, animations: {
  67. self.startButton.alpha = 1
  68. }) { (result) in
  69. }
  70. }else{
  71. pageControl.isHidden = false
  72. UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .allowAnimatedContent, animations: {
  73. self.startButton.alpha = 0
  74. }) { (result) in
  75. }
  76. }
  77. }
  78. @IBAction func startAppAction(_ sender: Any) {
  79. var login: LoginViewController?
  80. if self.presentingViewController is LoginViewController {
  81. DDLogDebug(" presenting is LoginViewController。")
  82. login = self.presentingViewController as? LoginViewController
  83. }
  84. self.dismiss(animated: true, completion: {
  85. DDLogDebug("关闭引导。。。。。。。。。。。。。。")
  86. if let lo = login {
  87. DDLogDebug(" 开始继续 LoginViewController。")
  88. lo.startFlowForPromise()
  89. }
  90. })
  91. }
  92. }