//
|
// 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) {
|
}
|
}
|