No Description

LoginViewController.swift 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // LoginViewController.swift
  3. // Paiai_iOS
  4. //
  5. // Created by FFIB on 16/4/17.
  6. // Copyright © 2016年 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. import PaiaiDataKit
  10. import PaiaiUIKit
  11. import RxSwift
  12. final class LoginViewController: UIViewController {
  13. @IBOutlet weak var pageControl: UIPageControl!
  14. @IBOutlet weak var scrollView: UIScrollView!
  15. @IBOutlet weak var guestLoginBtn: UIButton!
  16. @IBOutlet weak var weixinLoginBtn: UIButton!
  17. public var userInfoViewModel: UserInfoViewModel!
  18. fileprivate var disposeBag = DisposeBag()
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. binding()
  22. setProperties()
  23. }
  24. func setProperties() {
  25. if #available(iOS 11, *) { return }
  26. automaticallyAdjustsScrollViewInsets = false
  27. }
  28. }
  29. /// binding UI
  30. extension LoginViewController {
  31. func binding() {
  32. bindInteraction()
  33. bindScrollViewDelegate()
  34. }
  35. func bindInteraction() {
  36. guestLoginBtn.rx.tap
  37. .bind(to: userInfoViewModel.guestLoginBtnTapped)
  38. .disposed(by: disposeBag)
  39. weixinLoginBtn.rx.tap
  40. .bind(to: userInfoViewModel.wxLoginBtnTapped)
  41. .disposed(by: disposeBag)
  42. }
  43. func bindScrollViewDelegate() {
  44. scrollView.rx.didEndDecelerating
  45. .asDriver()
  46. .drive(onNext: {[weak self] (_) in
  47. guard let `self` = self else { return }
  48. self.pageControl.currentPage = Int(self.scrollView.contentOffset.x/self.view.width)
  49. }).disposed(by: disposeBag)
  50. scrollView.rx.didScroll
  51. .asDriver()
  52. .drive(onNext: {[weak self] (_) in
  53. guard let `self` = self else { return }
  54. if self.scrollView.contentOffset.x/self.view.width < 2 {
  55. self.weixinLoginBtn.isHidden = true
  56. self.guestLoginBtn.isHidden = true
  57. } else {
  58. #if (arch(i386) || arch(x86_64))
  59. self.weixinLoginBtn.isHidden = false
  60. #else
  61. self.weixinLoginBtn.isHidden = !WXApi.isWXAppInstalled()
  62. #endif
  63. self.guestLoginBtn.isHidden = false
  64. }
  65. }).disposed(by: disposeBag)
  66. }
  67. }
  68. extension LoginViewController: Storyboarded {
  69. static func instantiate() -> LoginViewController {
  70. return UIStoryboard.main.instantiateViewController(type: LoginViewController.self)
  71. }
  72. }