宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
//
//  TripInfoView.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/5.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
import RxCocoa
import RxSwift
 
class TripInfoView: UIView {
    @IBOutlet weak var view_police: YYView!
    @IBOutlet weak var image_inform: UIImageView!
    
    /// 通知
    @IBOutlet weak var view_notice: UIView!
    
    /// 客服
    @IBOutlet weak var button_service: UIButton!
    
    /// 报警
    @IBOutlet weak var button_police: UIButton!
    
    /// 定位
    @IBOutlet weak var button_position: UIButton!
    
    /// 广告视图
    var noticeView: GYRollingNoticeView!
    
    /// 回调
    var complete = Delegate<Int, Void>()
    
    /// 滚动数据源
    let dataSource = BehaviorRelay<[SwitchCityModel]>(value: [])
    
    /// 获取Self
    /// - Returns: Self
    class func instance() -> TripInfoView {
        let v = UINib(nibName: "TripInfoView", bundle: nil).instantiate(withOwner: self, options: nil).first as! TripInfoView
        v.setupViews()
        v.bindRx()
        return v
    }
 
    //MARK: - UI
    func setupViews() {
        noticeView = GYRollingNoticeView()
        view_police.backgroundColor = UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#FFFFFF"))
        button_police.backgroundColor = UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#FFFFFF"))
        button_service.backgroundColor = UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#FFFFFF"))
        noticeView.backgroundColor = UIColor.clear
        noticeView.delegate = self
        noticeView.dataSource = self
        view_notice.addSubview(noticeView)
        noticeView.register(UINib.init(nibName: "NoticeViewView", bundle: nil), forCellReuseIdentifier: "noticeItem")
        noticeView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
    
    //MARK: - Rx
    func bindRx() {
        button_position.rx.tap.subscribe(onNext: {[unowned self] (_) in
            self.button_position.isUserInteractionEnabled = false
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                self.button_position.isUserInteractionEnabled = true
            }
            self.complete.call(1)
        }).disposed(by: rx.disposeBag)
        
        button_police.rx.tap.subscribe(onNext: {[unowned self] (_) in
            self.button_police.isUserInteractionEnabled = false
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                self.button_police.isUserInteractionEnabled = true
            }
            self.complete.call(2)
        }).disposed(by: rx.disposeBag)
        
        button_service.rx.tap.subscribe(onNext: {[unowned self] (_) in
            self.button_service.isUserInteractionEnabled = false
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                self.button_service.isUserInteractionEnabled = true
            }
            self.complete.call(3)
        }).disposed(by: rx.disposeBag)
    }
    
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        //将当前触摸点转换坐标系生成一个新的点
//        let position = self.convert(point, to: button_position)
//        let police = self.convert(point, to: button_police)
//        let service = self.convert(point, to: button_service)
//        let notice = self.convert(point, to: view_notice)
//        if self.button_position.point(inside: position, with: event) || self.button_police.point(inside: police, with: event) || self.button_service.point(inside: service, with: event) || self.view_notice.point(inside: notice, with: event){
//            return super.hitTest(point, with: event)
//        }else{
//            return nil
//        }
        if self.point(inside: point, with: event) {
            for subView in subviews.first?.subviews ?? [] {
                let coverPoint = subView.convert(point, from: self)
                let hitTestView = subView.hitTest(coverPoint, with: event)
                if let hitTestView = hitTestView {
                    return hitTestView
                }
            }
            
        }
        
        return nil
    }
}
// MARK: - GYRollingNoticeViewDelegate,GYRollingNoticeViewDataSource
extension TripInfoView:GYRollingNoticeViewDelegate,GYRollingNoticeViewDataSource{
    func numberOfRowsFor(roolingView: GYRollingNoticeView) -> Int {
        return dataSource.value.count
    }
    
    func rollingNoticeView(roolingView: GYRollingNoticeView, cellAtIndex index: Int) -> GYNoticeViewCell {
        let cell = roolingView.dequeueReusableCell(withIdentifier: "noticeItem") as! NoticeViewView
        cell.onReuse(title: dataSource.value[index].content)
        return cell
    }
    func rollingNoticeView(_ roolingView: GYRollingNoticeView, didClickAt index: Int) {
    }
}