//
|
// MineBirthdayView.swift
|
// OKProject
|
//
|
// Created by alvin_y on 2020/6/15.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
class MineBirthdayView: UIView {
|
|
/// viewModel
|
let viewModel = MineInfoViewModel()
|
|
/// UIDatePicker
|
@IBOutlet weak var datePicker: UIDatePicker!
|
|
/// 取消
|
@IBOutlet weak var button_cancel: UIButton!
|
|
/// 提交
|
@IBOutlet weak var button_submit: UIButton!
|
|
/// 容器
|
@IBOutlet weak var view_container: YYView!
|
|
typealias MineMineBirthdayBlock = (String) -> ()
|
|
/// 成功
|
var mineInBlock: MineMineBirthdayBlock?
|
private var maximumDate:Date?
|
|
/// 获取Self
|
/// - Returns: Self
|
class func instance() -> MineBirthdayView {
|
let v = UINib(nibName: "MineBirthdayView", bundle: nil).instantiate(withOwner: self, options: nil).first as! MineBirthdayView
|
v.setupViews()
|
v.bindRx()
|
return v
|
}
|
|
//MARK: - UI
|
func setupViews() {
|
self.frame = UIScreen.main.bounds
|
self.view_container.transform = CGAffineTransform.init(translationX: 0, y: screenH)
|
self.backgroundColor = UIColor.color(light: UIColor.color(hexString: "#000000",0.5), dark: UIColor.color(hexString: "#000000",0.61))
|
|
datePicker.maximumDate = maximumDate
|
if #available(iOS 13.4, *) {
|
datePicker.preferredDatePickerStyle = .wheels
|
} else {
|
|
}
|
}
|
|
|
//MARK: - Rx
|
func bindRx() {
|
|
button_submit.rx.tap.subscribe(onNext: {[unowned self] (_) in
|
let chooseDate = self.datePicker.date
|
let dateFormater = DateFormatter.init()
|
dateFormater.dateFormat = "yyyy-MM-dd"
|
self.dismiss()
|
self.mineInBlock?("\(dateFormater.string(from: chooseDate))")
|
}).disposed(by: rx.disposeBag)
|
|
button_cancel.rx.tap.subscribe(onNext: {[unowned self] (_) in
|
self.dismiss()
|
}).disposed(by: rx.disposeBag)
|
}
|
|
/// 显示
|
func show(_ maximumDate:Date? = Date(), success: @escaping (String) -> ()) {
|
self.mineInBlock = success
|
self.maximumDate = maximumDate
|
self.datePicker.maximumDate = maximumDate
|
app.window?.addSubview(self)
|
UIView.animate(withDuration: 0.2) {
|
self.view_container.transform = CGAffineTransform.identity
|
}
|
}
|
|
/// 隐藏
|
func dismiss() {
|
UIView.animate(withDuration: 0.2, animations: {
|
self.view_container.transform = CGAffineTransform.init(translationX: 0, y: screenH)
|
}) { (_) in
|
self.removeFromSuperview()
|
}
|
|
}
|
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
var point: CGPoint? = touches.first?.location(in: self)
|
point = view_container.layer.convert(point ?? CGPoint.zero, from: self.layer)
|
if view_container.layer.contains(point ?? CGPoint.zero) {
|
//处理点击到这个view中要执行的事件
|
return
|
}
|
super.touchesBegan(touches, with: event)
|
self.dismiss()
|
}
|
}
|