Commit 3458b157 authored by pete谢兆麟's avatar pete谢兆麟

Merge branch 'xiezhaolin' into develop

parents 219f73a0 9d754662
This diff is collapsed.
......@@ -89,16 +89,6 @@ class YHMainApplicantInformationViewController: YHBaseViewController {
make.left.right.bottom.equalTo(view)
make.height.equalTo(k_Height_safeAreaInsetsBottom() + 64)
}
stepView.isHidden = true
tableView.isHidden = true
bottomView.isHidden = true
let datePicker = UIDatePicker(frame: CGRect(x: 0, y: 150, width: self.view.bounds.width, height: 200))
datePicker.datePickerMode = .dateAndTime
// datePicker.addTarget(self, action: #selector(handleDateChange), for: .valueChanged)
// 将日期选择器添加到视图上
self.view.addSubview(datePicker)
}
}
......@@ -126,7 +116,7 @@ extension YHMainApplicantInformationViewController: UITableViewDelegate, UITable
if stepView.currentIndex == 1 {
return 217.0
} else {
return CGFloat(count * 52 + 52 + 14)
return CGFloat(count * 52 + 52 + 14)
}
}
}
//
// YHDatePickView.swift
// galaxy
//
// Created by EDY on 2024/1/30.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import Foundation
struct YHCountryModel {
var provincesArray: [YHProvincesModel] = []
init(dic: [String:[String:[String]]]) {
for (key,value) in dic {
let model = YHProvincesModel(name: key, dic: value)
provincesArray.append(model)
provincesArray.sort { a, b in
a.provincesName < b.provincesName
}
}
}
}
struct YHProvincesModel {
var provincesName: String = ""
var cityArray: [YHCityModel] = []
init(name : String ,dic:[String: [String]]) {
provincesName = name
for (key,value) in dic {
let model = YHCityModel(name: key, Arr: value)
cityArray.append(model)
cityArray.sort { a, b in
a.cityName < b.cityName
}
}
}
}
struct YHCityModel {
var cityName: String = ""
var areaArray: [String] = []
init(name: String,Arr: [String]) {
cityName = name
for str in Arr {
areaArray.append(str)
}
areaArray.sort(by: <)
}
}
//
// YHDatePickView.swift
// galaxy
//
// Created by EDY on 2024/1/30.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHAddressPickViewTableViewCell: UITableViewCell {
static let identifier = "YHAddressPickViewTableViewCell"
let label: UILabel = {
let label = UILabel(frame: CGRect(x: 42, y: 8, width: 200, height: 24))
label.font = UIFont.systemFont(ofSize: 14)
label.textColor = UIColor(red: 51/255, green: 51/255, blue: 51/255, alpha: 1)
return label
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
drawMyView()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func drawMyView() {
self.addSubview(label)
}
}
class YHAddressPickViewFirstTableViewCell: UITableViewCell {
static let identifier = "YHAddressPickViewFirstTableViewCell"
let label: UILabel = {
let label = UILabel(frame: CGRect(x: 24, y: 11.5, width: 100, height: 17))
label.font = UIFont.systemFont(ofSize: 12)
label.textColor = UIColor(red: 102/255, green: 102/255, blue: 102/255, alpha: 1)
return label
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
drawMyView()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func drawMyView() {
self.addSubview(label)
}
}
//
// YHDatePickView.swift
// galaxy
//
// Created by EDY on 2024/1/30.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
enum YHAddressPickerPresentAnimateType {
case present//被推出时
case dismiss//取消时
}
//EWAddressPickerViewController的推出和取消动画
class YHAddressPickerPresentAnimated: NSObject,UIViewControllerAnimatedTransitioning {
var type: YHAddressPickerPresentAnimateType = .present
init(type: YHAddressPickerPresentAnimateType) {
self.type = type
}
/// 动画时间
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.3
}
/// 动画效果
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
switch type {
case .present:
guard let toVC: YHAddressViewController = transitionContext.viewController(forKey: .to) as? YHAddressViewController else {
return
}
let toView = toVC.view
let containerView = transitionContext.containerView
containerView.addSubview(toView!)
toVC.containV.transform = CGAffineTransform(translationX: 0, y: (toVC.containV.frame.height))
UIView.animate(withDuration: 0.25, animations: {
/// 背景变色
toVC.backgroundView.alpha = 1.0
/// addresspicker向上推出
toVC.containV.transform = CGAffineTransform(translationX: 0, y: -10)
}) { (_) in
UIView.animate(withDuration: 0.2, animations: {
/// transform初始化
toVC.containV.transform = CGAffineTransform.identity
}, completion: { (_) in
transitionContext.completeTransition(true)
})
}
case .dismiss:
guard let toVC: YHAddressViewController = transitionContext.viewController(forKey: .from) as? YHAddressViewController else {
return
}
UIView.animate(withDuration: 0.25, animations: {
toVC.backgroundView.alpha = 0.0
/// addresspicker向下推回
toVC.containV.transform = CGAffineTransform(translationX: 0, y: (toVC.containV.frame.height))
}) { (_) in
transitionContext.completeTransition(true)
}
}
}
}
//
// YHDatePickView.swift
// galaxy
//
// Created by EDY on 2024/1/30.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
/*
let addressPicker = YHAddressViewController( selectProvince: "上海市", selectCity: "" )
/*** 可使用这种init方法自定制选中颜色,不填写selectColor默认颜色为UIColor(red: 79/255, green: 176/255, blue: 255/255, alpha: 1),蓝色
let addressPicker = EWAddressViewController(selectColor: UIColor.yellow)
*/
// 返回选择数据,地址,省,市,区
addressPicker.backLocationStringController = { (address,province,city,area) in
}
self.present(addressPicker, animated: true, completion: nil)
*/
import UIKit
///默认选中颜色
let defaultColor = UIColor(red: 79/255, green: 176/255, blue: 255/255, alpha: 1)
class YHAddressViewController: UIViewController {
public var backLocationStringController: ((String,String,String,String) -> Void)?
///title选中颜色
public var selectColor: UIColor
public var selectProvince: String?
public var selectCity: String?
public lazy var containV: YHAddressPickView = {
let view = YHAddressPickView(frame: CGRect(x: 0, y: UIScreen.main.bounds.height - 550, width: UIScreen.main.bounds.width, height: 550),selectColor: selectColor,selectedProvince: selectProvince,selectedCity: selectCity)
view.backOnClickCancel = {
[weak self] in
self?.onClickCancel()
}
/// 成功选择后将数据回调,并推出视图
view.backLocationString = {[weak self] (address,province,city,area) in
if self?.backLocationStringController != nil {
self?.backLocationStringController!(address,province,city,area)
self?.onClickCancel()
}
}
return view
}()
public var backgroundView:UIView = {
let view = UIView()
view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.4)
return view
}()
init(selectColor: UIColor = defaultColor,selectProvince: String? = nil, selectCity: String? = nil) {
self.selectColor = selectColor
self.selectProvince = selectProvince
self.selectCity = selectCity
super.init(nibName: nil, bundle: nil)
self.view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
drawMyView()
// Do any additional setup after loading the view.
}
private func drawMyView() {
self.view.insertSubview(self.backgroundView, at: 0)
self.providesPresentationContextTransitionStyle = true
self.definesPresentationContext = true
self.modalPresentationStyle = .custom//viewcontroller弹出后之前控制器页面不隐藏 .custom代表自定义
self.view.addSubview(self.containV)
// 转场动画代理
self.transitioningDelegate = self
}
///点击推出
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let currentPoint = touches.first?.location(in: self.view)
if !self.containV.frame.contains(currentPoint ?? CGPoint()) {
self.dismiss(animated: true, completion: nil)
}
}
// MARK: onClick
@objc private func onClickCancel() {
self.dismiss(animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
// MARK: - 转场动画delegate
extension YHAddressViewController: UIViewControllerTransitioningDelegate {
/// 推入动画
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let animated = YHAddressPickerPresentAnimated(type: .present)
return animated
}
/// 推出动画
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let animated = YHAddressPickerPresentAnimated(type: .dismiss)
return animated
}
}
//
// YHDatePickView.swift
// galaxy
//
// Created by EDY on 2024/1/30.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
/* 使用例子
let view = YHDatePickView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight))
view.type = .yyyymm
view.backDate = { [weak self] date in
}
let window = UIApplication.shared.yhKeyWindow()
window?.addSubview(view)
*/
import UIKit
enum YHDateType: Int {
case yyyymmdd = 0
case yyyymm = 1
case yyyy = 2
}
class YHDatePickView: UIView {
var backDate: ((String) -> Void)?
var centerView: UIView!
var titleLabel: UILabel!
var closeButton: UIButton!
var sureButton: UIButton!
var lineView: UIView!
var pickerView: UIPickerView!
private var currentDateCom: DateComponents = Calendar.current.dateComponents([.year, .month, .day], from: Date())
var type: YHDateType? {
didSet {
guard let type = type else { return }
switch type {
case .yyyymmdd:
pickerView.reloadAllComponents()
case .yyyymm:
pickerView.reloadAllComponents()
case .yyyy:
pickerView.reloadAllComponents()
}
}
}
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(white: 0.5, alpha: 0.1)
let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
tap.delegate = self
addGestureRecognizer(tap)
setView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setView() {
backgroundColor = UIColor(hex: 0x0000, alpha: 0.5)
centerView = {
let view = UIView()
view.backgroundColor = .white
view.layer.cornerRadius = 16
return view
}()
addSubview(centerView)
centerView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.height.equalTo(322)
}
titleLabel = {
let label = UILabel()
label.text = "选择出生日期"
label.font = kFont(size: 17)
label.textColor = UIColor(hex:0x222222)
label.textAlignment = .center
return label
}()
centerView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.top.equalTo(16)
make.height.equalTo(21)
make.width.equalTo(200)
make.centerX.equalToSuperview()
}
closeButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = kBoldFont(size: 14)
button.contentHorizontalAlignment = .center
button.setTitle("取消", for: .normal)
button.setTitleColor( UIColor(hex:0x222222), for: .normal)
button.addTarget(self, action: #selector(dismiss), for: .touchUpInside)
return button
}()
centerView.addSubview(closeButton)
closeButton.snp.makeConstraints { make in
make.left.equalTo(21)
make.height.equalTo(20)
make.width.equalTo(30)
make.top.equalTo(18)
}
sureButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = kBoldFont(size: 14)
button.contentHorizontalAlignment = .center
button.setTitle("确定", for: .normal)
button.setTitleColor( UIColor(hex:0x4487f9), for: .normal)
button.addTarget(self, action: #selector(sure), for: .touchUpInside)
return button
}()
centerView.addSubview(sureButton)
sureButton.snp.makeConstraints { make in
make.right.equalTo(-21)
make.height.equalTo(20)
make.width.equalTo(30)
make.top.equalTo(18)
}
lineView = {
let view = UIView()
view.backgroundColor = UIColor(hex: 0xf0f0f0)
return view
}()
centerView.addSubview(lineView)
lineView.snp.makeConstraints { make in
make.left.equalTo(18)
make.top.equalTo(52)
make.height.equalTo(1)
make.right.equalTo(-18)
}
pickerView = {
let picker = UIPickerView()
picker.delegate = self
picker.dataSource = self
picker.backgroundColor = UIColor.clear
picker.clipsToBounds = true
return picker
}()
centerView.addSubview(pickerView)
pickerView.snp.makeConstraints { make in
make.left.equalTo(16)
make.top.equalTo(68)
make.height.equalTo(220)
make.right.equalTo(-16)
}
}
@objc private func handleTap(_ sender: AnyObject?) {
print("处理点击手势")
dismiss()
}
@objc func dismiss() {
removeFromSuperview()
}
@objc func sure() {
guard let type = type else { return }
var date = ""
switch type {
case .yyyymmdd:
date = String(format: "%02ld%02ld%02ld", (self.currentDateCom.year!) - self.pickerView.selectedRow(inComponent: 0), self.pickerView.selectedRow(inComponent: 1) + 1, self.pickerView.selectedRow(inComponent: 2) + 1)
case .yyyymm:
date = String(format: "%02ld%02ld", (self.currentDateCom.year!) - self.pickerView.selectedRow(inComponent: 0), self.pickerView.selectedRow(inComponent: 1) + 1)
case .yyyy:
date = String(format: "%02ld", (self.currentDateCom.year!) - self.pickerView.selectedRow(inComponent: 0))
}
if self.backDate != nil {
self.backDate!(date)
}
}
}
extension YHDatePickView: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer:UIGestureRecognizer, shouldReceive touch:UITouch) -> Bool {
if touch.view == self {
return true
}
return false
}
}
extension YHDatePickView: UIPickerViewDelegate,UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
guard let type = type else { return 3 }
switch type {
case .yyyymmdd:
return 3
case .yyyymm:
return 2
case .yyyy:
return 1
}
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0 {
return 100
} else if component == 1 {
return 12
} else {
let year: Int = pickerView.selectedRow(inComponent: 0) + currentDateCom.year!
let month: Int = pickerView.selectedRow(inComponent: 1) + 1
let days: Int = howManyDays(inThisYear: year, withMonth: month)
return days
}
}
private func howManyDays(inThisYear year: Int, withMonth month: Int) -> Int {
if (month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12) {
return 31
}
if (month == 4) || (month == 6) || (month == 9) || (month == 11) {
return 30
}
if (year % 4 == 1) || (year % 4 == 2) || (year % 4 == 3) {
return 28
}
if year % 400 == 0 {
return 29
}
if year % 100 == 0 {
return 28
}
return 29
}
func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
guard let type = type else { return KScreenWidth / 3 }
switch type {
case .yyyymmdd:
return KScreenWidth / 3
case .yyyymm:
return KScreenWidth / 2
case .yyyy:
return KScreenWidth
}
}
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 44
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if component == 0 {
return "\((currentDateCom.year!) - row)"
} else if component == 1 {
return "\(row + 1)"
} else {
return "\(row + 1)"
}
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if component == 1, self.type == .yyyymmdd {
pickerView.reloadComponent(2)
}
}
}
//
// YHImagePickerView.swift
// galaxy
//
// Created by EDY on 2024/1/30.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHImagePickerView: UIView {
var centerView: UIView!
var titleLabel: UILabel!
var closeButton: UIButton!
var lineView: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(white: 0.5, alpha: 0.1)
let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
tap.delegate = self
addGestureRecognizer(tap)
setView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setView() {
backgroundColor = UIColor(hex: 0x0000, alpha: 0.5)
centerView = {
let view = UIView()
view.backgroundColor = .white
view.layer.cornerRadius = 16
return view
}()
addSubview(centerView)
centerView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.height.equalTo(244)
}
titleLabel = {
let label = UILabel()
label.text = "选择出生日期"
label.font = kFont(size: 17)
label.textColor = UIColor(hex:0x222222)
label.textAlignment = .left
return label
}()
centerView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.top.equalTo(16)
make.left.height.equalTo(21)
make.right.equalTo(-21)
}
closeButton = {
let button = UIButton(type: .custom)
button.setBackgroundImage(UIImage(named: "service_card_close"), for: .normal)
button.addTarget(self, action: #selector(dismiss), for: .touchUpInside)
return button
}()
centerView.addSubview(closeButton)
closeButton.snp.makeConstraints { make in
make.right.equalTo(-21)
make.width.height.equalTo(24)
make.top.equalTo(16)
}
lineView = {
let view = UIView()
view.backgroundColor = UIColor(hex: 0xf0f0f0)
return view
}()
centerView.addSubview(lineView)
lineView.snp.makeConstraints { make in
make.left.equalTo(18)
make.top.equalTo(52)
make.height.equalTo(1)
make.right.equalTo(-18)
}
}
@objc private func handleTap(_ sender: AnyObject?) {
print("处理点击手势")
dismiss()
}
@objc func dismiss() {
removeFromSuperview()
}
}
extension YHImagePickerView: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer:UIGestureRecognizer, shouldReceive touch:UITouch) -> Bool {
if touch.view == self {
return true
}
return false
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment