Commit e3c17213 authored by lujunye's avatar lujunye

搜索界面

parent 43b8edb2
......@@ -13,7 +13,7 @@ import AMapFoundationKit
import MAMapKit
import AMapSearchKit
import IQKeyboardManagerSwift
class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLocationManagerDelegate, AMapSearchDelegate {
class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLocationManagerDelegate, AMapSearchDelegate, UISearchBarDelegate, SearchBarViewDelegate {
@IBOutlet weak var navBgView: UIView!
@IBOutlet weak var citySelectBtn: UIButton!
......@@ -34,14 +34,40 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
var lng:CLLocationDegrees = 0
var manger:CLLocationManager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
manger.stopUpdatingLocation()
let location = locations.last
lat = location?.coordinate.latitude as! CLLocationDegrees
lng = location?.coordinate.longitude as! CLLocationDegrees
initMapView(lat: lat, lng: lng)
initSearch()
@IBOutlet weak var lineX: NSLayoutConstraint!
@IBOutlet weak var closeBtn: UIButton!
@IBAction func closeAction(_ sender: Any) {
closeBtn.isHidden = true
listViewBG.isHidden = true
IQKeyboardManager.shared.resignFirstResponder()
}
@IBOutlet weak var rightBtn: UIButton!
@IBOutlet weak var leftBtn: UIButton!
@IBAction func listViewRefresh(_ sender: UIButton) {
if sender == leftBtn {
leftBtn.isSelected = true
rightBtn.isSelected = false
lineX.constant = 0
}else{
leftBtn.isSelected = false
rightBtn.isSelected = true
lineX.constant = fullScreenWidth * 0.5
}
}
@IBOutlet weak var listViewBG: UIView!
@IBAction func backToUserLocation(_ sender: Any) {
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
listViewBG.layer.cornerRadius = 5
listViewBG.layer.maskedCorners = [CACornerMask.layerMinXMinYCorner,CACornerMask.layerMaxXMinYCorner]
}
override func viewDidLoad() {
super.viewDidLoad()
......@@ -56,12 +82,25 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
}
searchBr.placeholderStr = "从哪儿发货"
searchBr.cornerRadius = 35/2.0
searchBr.delegate = self
searchBr.delegateL = self
AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a"
manger.delegate = self
manger.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
manger.stopUpdatingLocation()
let location = locations.last
lat = location?.coordinate.latitude as! CLLocationDegrees
lng = location?.coordinate.longitude as! CLLocationDegrees
initMapView(lat: lat, lng: lng)
initSearch()
}
func initMapView(lat:CLLocationDegrees,lng:CLLocationDegrees) {
AMapServices.shared().enableHTTPS = true
......@@ -98,6 +137,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
var introView:UIView?
var titleLbl:UILabel?
var contentLbl:UILabel?
var adrArr:Array<AMapPOI> = []
func onPOISearchDone(_ request: AMapPOISearchBaseRequest!, response: AMapPOISearchResponse!) {
......@@ -105,6 +145,12 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
return
}
//解析response获取POI信息,具体解析见 Demo
adrArr.removeAll()
response.pois.forEach { (poi) in
adrArr.append(poi)
}
print(adrArr.count)
if introView == nil {
introView = UIView()
......@@ -125,11 +171,21 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
introView?.addSubview(contentLbl!)
}
titleLbl!.text = response.pois.first?.name
contentLbl!.text = "\(String(describing: response.pois.first!.province!))\(String(describing: response.pois.first!.city!))\(String(describing: response.pois.first!.district!))\( String(describing: response.pois.first!.address!))"
//通过富文本来设置行间距
let paraph = NSMutableParagraphStyle()
//将行间距设置为28
paraph.lineSpacing = 3
let str = "\(String(describing: response.pois.first!.province!))\(String(describing: response.pois.first!.city!))\(String(describing: response.pois.first!.district!))\( String(describing: response.pois.first!.address!))"
let attributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 11),
NSAttributedString.Key.paragraphStyle: paraph]
contentLbl!.attributedText = NSAttributedString(string: str, attributes: attributes)
let t = getStrHeight(str: titleLbl!.text!, fontSize: 13)
let c = getStrHeight(str: contentLbl!.text!, fontSize: 11)
let c = getStrHeight(str: str, fontSize: 11)
let h = t+c
titleLbl?.snp_updateConstraints({ (make) in
......@@ -138,9 +194,9 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
make.right.equalTo(-10)
make.height.equalTo(t)
})
contentLbl?.snp_updateConstraints({ (make) in
make.top.equalTo(titleLbl!.snp.bottom).offset(5)
make.top.equalTo(titleLbl!.snp_bottom).offset(5)
make.left.equalTo(10)
make.right.equalTo(-10)
make.height.equalTo(c)
......@@ -174,7 +230,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
})
}
func getStrHeight(str:String,fontSize:CGFloat) -> CGFloat{
let lbl = UILabel()
lbl.text = str
......@@ -246,5 +302,28 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
let bdlat = z * sin(theta) + 0.006
return (bdlat,bdlon)
}
func clearSearchAction() {
print("清楚搜索文字")
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("点击搜索进行--")
searchBar.resignFirstResponder()
let request = AMapPOIKeywordsSearchRequest()
request.keywords = searchBar.text
request.requireExtension = true
request.cityLimit = true
request.requireSubPOIs = true
search.aMapPOIKeywordsSearch(request)
}
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
print("调起搜索后添加个蒙版本")
closeBtn.isHidden = false
listViewBG.isHidden = false
return true
}
}
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