younger_times
2023-08-15 2ebbafa4b4a2994ae979fed38e1266d9efd5657e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
//  HomeVC.swift
//  BrokerDriver
//
//  Created by 无故事王国 on 2023/4/24.
//
 
import UIKit
import FFPage
import SPPageMenu
import CoreLocation
 
class HomeVC: BaseViewController {
 
    lazy var adapterViewController:FFAdapterViewController = {
        let adapterViewController = FFAdapterViewController()
        adapterViewController.headHeight = JQ_ScreenW * 0.50
        adapterViewController.menuHeight = 108
        adapterViewController.style = .headEnlarge
        adapterViewController.ignoreTopSpeace = topSafeHeight
        adapterViewController.headViewController = headerViewController
        adapterViewController.menuViewController = menuViewController
        adapterViewController.pageViewController = pageViewController
        return adapterViewController
    }()
 
    lazy var pageViewController:FFPageViewController = {
        let pageViewController = FFPageViewController()
        pageViewController.delegate = self
        return pageViewController
    }()
 
    lazy var headerViewController:HomeHeaderVC = {
        let vc = HomeHeaderVC()
        return vc
    }()
 
    lazy var menuViewController:HomeMenuVC = {
        let vc = HomeMenuVC()
        return vc
    }()
 
    private lazy var manager:CLLocationManager = {
        let mana = CLLocationManager()
        mana.delegate = self
        mana.requestAlwaysAuthorization()
        mana.distanceFilter = 20
        mana.desiredAccuracy = 10
        return mana
    }()
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        manager.startUpdatingLocation()
 
    }
 
    override func setUI() {
        super.setUI()
        navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "icon_profile")!.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(profileAction))
 
        addChild(adapterViewController)
        view.insertSubview(adapterViewController.view, at: 0)
        adapterViewController.didMove(toParent: self)
        adapterViewController.view.frame = view.frame
        menuViewController.pageMenu.delegate = self
        menuViewController.pageMenu.bridgeScrollView = pageViewController.scrollview
    }
 
    @objc func profileAction(){
        let vc = PersonalCenterVC()
        push(vc: vc)
    }
}
 
 
extension HomeVC:SPPageMenuDelegate{
    func pageMenu(_ pageMenu: SPPageMenu, itemSelectedAt index: Int) {
        self.pageViewController.scroll(toPage: index, animation: true)
    }
}
 
extension HomeVC:FFPageViewControllerDelegate {
 
    func pageViewController(_ pageViewController: FFPageViewController, currentPageChanged currentPage: Int) {
        menuViewController.pageMenu.selectedItemIndex = currentPage
        if currentPage == 0{
            adapterViewController.menuHeight = 108
        }else{
            adapterViewController.menuHeight = 47
        }
        adapterViewController.updateHeight(withAnimation: true)
    }
 
    func totalPagesOfpageViewController(_ pageViewConteoller: FFPageViewController) -> UInt {
        return 2
    }
 
    func pageViewController(_ pageViewConteoller: FFPageViewController, controllerForPage page: Int) -> UIViewController {
        if page == 0{
             let vc = HomePageVC(style: .progress)
            vc.box = menuViewController.box
            vc.adapterViewController = adapterViewController
            return vc
        }
 
        if page == 1{
            let vc = HomePageVC(style: .complete)
            vc.adapterViewController = adapterViewController
            return vc
        }
        return UIViewController()
 
    }
}
 
extension HomeVC:CLLocationManagerDelegate{
    func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
 
    }
 
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        if let location = locations.last{
            Services.uploadLocation(coordinate: location.coordinate).subscribe(onNext: {data in
 
            }).disposed(by: disposeBag)
        }
    }
}