1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import UIKit
- import PaiaiDataKit
- import PaiaiUIKit
- import RxSwift
- final class LoginViewController: UIViewController {
- @IBOutlet weak var pageControl: UIPageControl!
- @IBOutlet weak var scrollView: UIScrollView!
- @IBOutlet weak var guestLoginBtn: UIButton!
- @IBOutlet weak var weixinLoginBtn: UIButton!
- public var userInfoViewModel: UserInfoViewModel!
- fileprivate var disposeBag = DisposeBag()
- override func viewDidLoad() {
- super.viewDidLoad()
- binding()
- setProperties()
- }
- func setProperties() {
- if #available(iOS 11, *) { return }
- automaticallyAdjustsScrollViewInsets = false
- }
- }
- extension LoginViewController {
- func binding() {
- bindInteraction()
- bindScrollViewDelegate()
- }
- func bindInteraction() {
- guestLoginBtn.rx.tap
- .bind(to: userInfoViewModel.guestLoginBtnTapped)
- .disposed(by: disposeBag)
- weixinLoginBtn.rx.tap
- .bind(to: userInfoViewModel.wxLoginBtnTapped)
- .disposed(by: disposeBag)
- }
- func bindScrollViewDelegate() {
- scrollView.rx.didEndDecelerating
- .asDriver()
- .drive(onNext: {[weak self] (_) in
- guard let `self` = self else { return }
- self.pageControl.currentPage = Int(self.scrollView.contentOffset.x/self.view.width)
- }).disposed(by: disposeBag)
- scrollView.rx.didScroll
- .asDriver()
- .drive(onNext: {[weak self] (_) in
- guard let `self` = self else { return }
- if self.scrollView.contentOffset.x/self.view.width < 2 {
- self.weixinLoginBtn.isHidden = true
- self.guestLoginBtn.isHidden = true
- } else {
- #if (arch(i386) || arch(x86_64))
- self.weixinLoginBtn.isHidden = false
- #else
- self.weixinLoginBtn.isHidden = !WXApi.isWXAppInstalled()
- #endif
- self.guestLoginBtn.isHidden = false
- }
- }).disposed(by: disposeBag)
- }
- }
- extension LoginViewController: Storyboarded {
- static func instantiate() -> LoginViewController {
- return UIStoryboard.main.instantiateViewController(type: LoginViewController.self)
- }
- }
|