younger_times
2023-07-14 ca2a4ce89064be715e90ae60dc305c26e7dd5719
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
//
//  CityChooseSubTypeView.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/13.
//
 
import UIKit
import JQTools
 
class CityChooseSubTypeView: UIView,JQNibView{
    @IBOutlet weak var cons_viewHeight: NSLayoutConstraint!
    @IBOutlet weak var label_city: UILabel!
    private var closeClouse:(()->Void)?
    private var clouse:((String)->Void)?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        cons_viewHeight.constant = 100
        alpha = 0
        layoutIfNeeded()
        startLocation()
    }
 
    @discardableResult
    static func show(inView:UIView,afterView:UIView,clouse:@escaping (String)->Void,closeClouse:@escaping ()->Void)->CityChooseSubTypeView{
        let subTypeView = CityChooseSubTypeView.jq_loadNibView()
        subTypeView.closeClouse = closeClouse
        subTypeView.clouse = clouse
        inView.addSubview(subTypeView)
        subTypeView.snp.makeConstraints { make in
            make.top.equalTo(afterView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        
        UIView.animate(withDuration: 0.2) {
            subTypeView.alpha = 1
        } completion: { _ in
            subTypeView.cons_viewHeight.constant = JQ_ScreenH - 175  - UIDevice.jq_safeEdges.top - JQ_NavBarHeight
            UIView.animate(withDuration: 0.2) {
                subTypeView.layoutIfNeeded()
            }
        }
        return subTypeView
    }
    
    
    @IBAction func closeAction(_ sender: UIButton) {
        self.cons_viewHeight.constant = 100
        UIView.animate(withDuration: 0.2) {
            self.alpha = 0
            self.layoutIfNeeded()
        } completion: { _ in
            self.removeFromSuperview()
            self.closeClouse!()
        }
    }
 
    private func startLocation(){
        locationTool.startLocation { location in
            locationTool.geocoder(location) { [weak self] marks, error in
                self?.label_city.text = marks?.last?.locality ?? "定位失败"
                locationTool.stopLocation()
            }
        } errorClouse: { error in
            locationTool.stopLocation()
        }
    }
 
    @IBAction func reLocationAction(_ sender: Any) {
        startLocation()
    }
}