OOGuidePageController.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. class OOGuidePageController: UIViewController,UIScrollViewDelegate {
  10. @IBOutlet weak var containerView: UIScrollView!
  11. @IBOutlet weak var pageControl: UIPageControl!
  12. @IBOutlet weak var startButton: OOBaseUIButton!
  13. private var pageImageNames:[String] = ["引导页-1","引导页-2","引导页-3","引导页-4","引导页-5"]
  14. override func awakeFromNib() {
  15. //设置button
  16. }
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. title = "引导页"
  20. initPage()
  21. }
  22. private func initPage(){
  23. //容器
  24. self.containerView.contentSize = imagesContentSize()
  25. self.containerView.isDirectionalLockEnabled = true
  26. self.containerView.delegate = self
  27. self.containerView.isPagingEnabled = true
  28. self.containerView.showsHorizontalScrollIndicator = false
  29. imageViews().forEach { (imageView) in
  30. self.containerView.addSubview(imageView)
  31. }
  32. self.pageControl.numberOfPages = pageImageNames.count
  33. self.pageControl.currentPage = 0
  34. }
  35. @objc private func buttonClicked(_ sender:Any?){
  36. let url = URL(string:UIApplication.openSettingsURLString)!
  37. UIApplication.shared.openURL(url)
  38. }
  39. private func imagesContentSize() -> CGSize {
  40. let sHeight = SCREEN_WIDTH
  41. let sWidth = SCREEN_WIDTH * CGFloat(pageImageNames.count)
  42. return CGSize(width: sWidth, height: sHeight)
  43. }
  44. // MARK:- 返回图片页视图列表
  45. private func imageViews() -> [UIView] {
  46. var views:[UIView] = []
  47. for index in 0..<pageImageNames.count {
  48. let imageView = UIImageView(image: UIImage(named: pageImageNames[index]))
  49. imageView.frame = CGRect(x: (SCREEN_WIDTH * CGFloat(index)), y: 0, width: SCREEN_WIDTH
  50. , height: SCREEN_HEIGHT)
  51. views.append(imageView)
  52. }
  53. return views
  54. }
  55. override func didReceiveMemoryWarning() {
  56. super.didReceiveMemoryWarning()
  57. // Dispose of any resources that can be recreated.
  58. }
  59. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  60. //OOLog(scrollView.contentOffset)
  61. let currentPage = scrollView.contentOffset.x / scrollView.frame.size.width
  62. pageControl.currentPage = Int(currentPage)
  63. if pageControl.currentPage + 1 == pageControl.numberOfPages {
  64. pageControl.isHidden = true
  65. UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .allowAnimatedContent, animations: {
  66. self.startButton.alpha = 1
  67. }) { (result) in
  68. }
  69. }else{
  70. pageControl.isHidden = false
  71. UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .allowAnimatedContent, animations: {
  72. self.startButton.alpha = 0
  73. }) { (result) in
  74. }
  75. }
  76. }
  77. @IBAction func startAppAction(_ sender: Any) {
  78. self.dismiss(animated: true, completion: nil)
  79. }
  80. }