// // LocationPickerView.swift // QuickLocation // // Created by 八条 on 2026/6/24. // import UIKit import RxSwift import RxCocoa #if !targetEnvironment(simulator) import AMapNaviKit #endif class LocationPickerView: UIView { var disposeBag = DisposeBag() private func setupUI() { #if !targetEnvironment(simulator) addSubview(mapView) #endif addSubview(topBgView) topBgView.addSubview(backBtn) topBgView.addSubview(searchField) topBgView.addSubview(searchBtn) addSubview(resultTableView) addSubview(bottomView) bottomView.addSubview(poiNameLab) bottomView.addSubview(poiAddressLab) bottomView.addSubview(confirmBtn) mapView.layoutChain .edges() topBgView.layoutChain .top(kStatusBarHeight + 8) .edgesHorzontal(15) .height(44) backBtn.layoutChain .left().centerY() .width(36).height(36) searchField.layoutChain .leftToRightOfView(backBtn, offset: 8) .centerY() .right(60) .height(36) searchBtn.layoutChain .right(2).centerY() .width(80).height(36) resultTableView.layoutChain .topToBottomOfView(topBgView, offset: 10) .edgesHorzontal(15) bottomView.layoutChain .edgesHorzontal() .bottom() .height(160) poiNameLab.layoutChain .top(16).left(16).right(16) poiAddressLab.layoutChain .topToBottomOfView(poiNameLab, offset: 8) .left(16).right(16) confirmBtn.layoutChain .edgesHorzontal(30) .height(44) .bottom(kSafeBottomMargin + 16) } // MARK: - Views #if !targetEnvironment(simulator) lazy var mapView: MAMapView! = { let mv = MAMapView() mv.zoomLevel = 18 mv.showsUserLocation = false mv.showsCompass = false return mv }() #endif lazy var topBgView: UIView = { let v = UIView() v.backgroundColor = .white v.cornerRadius = 22 v.layer.shadowColor = UIColor.black.withAlphaComponent(0.1).cgColor v.layer.shadowOffset = .zero v.layer.shadowRadius = 6 v.layer.shadowOpacity = 1 return v }() lazy var backBtn: UIButton = { let btn = UIButton(type: .custom) btn.setImage(UIImage(named: "Common/back"), for: .normal) btn.extendEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8) return btn }() lazy var searchField: UITextField = { let tf = UITextField() tf.placeholder = "搜索地点、公园、商圈、道路" tf.font = .systemFont(ofSize: 14) tf.clearButtonMode = .whileEditing tf.returnKeyType = .search return tf }() lazy var searchBtn: UIButton = { let btn = UIButton(type: .custom) btn.setTitle("搜索", for: .normal) btn.setTitleColor(.white, for: .normal) btn.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium) btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal) btn.cornerRadius = 18 return btn }() lazy var resultTableView: UITableView = { let tv = UITableView(frame: .zero, style: .plain) tv.backgroundColor = .white tv.isHidden = true tv.register(UITableViewCell.self, forCellReuseIdentifier: "cell") tv.estimatedRowHeight = 60 tv.cornerRadius = 10 return tv }() lazy var bottomView: UIView = { let v = UIView() v.backgroundColor = .white v.isHidden = true v.layer.cornerRadius = 16 v.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] v.layer.shadowColor = UIColor.black.withAlphaComponent(0.1).cgColor v.layer.shadowOffset = CGSize(width: 0, height: -2) v.layer.shadowRadius = 10 v.layer.shadowOpacity = 1 return v }() lazy var poiNameLab: UILabel = { let l = UILabel() l.font = .systemFont(ofSize: 16, weight: .semibold) l.textColor = UIColor(hexStr: "#333333") return l }() lazy var poiAddressLab: UILabel = { let l = UILabel() l.font = .systemFont(ofSize: 13) l.textColor = UIColor(hexStr: "#999999") l.numberOfLines = 2 return l }() lazy var confirmBtn: UIButton = { let btn = UIButton(type: .custom) btn.setTitle("确定位置", for: .normal) btn.setTitleColor(.white, for: .normal) btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium) btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal) btn.cornerRadius = 22 return btn }() #if !targetEnvironment(simulator) func cleanupMap() { mapView?.delegate = nil mapView?.removeFromSuperview() mapView = nil } #endif override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .white setupUI() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }