Commit e3c17213 authored by lujunye's avatar lujunye

搜索界面

parent 43b8edb2
...@@ -13,7 +13,7 @@ import AMapFoundationKit ...@@ -13,7 +13,7 @@ import AMapFoundationKit
import MAMapKit import MAMapKit
import AMapSearchKit import AMapSearchKit
import IQKeyboardManagerSwift import IQKeyboardManagerSwift
class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLocationManagerDelegate, AMapSearchDelegate { class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLocationManagerDelegate, AMapSearchDelegate, UISearchBarDelegate, SearchBarViewDelegate {
@IBOutlet weak var navBgView: UIView! @IBOutlet weak var navBgView: UIView!
@IBOutlet weak var citySelectBtn: UIButton! @IBOutlet weak var citySelectBtn: UIButton!
...@@ -34,14 +34,40 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -34,14 +34,40 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
var lng:CLLocationDegrees = 0 var lng:CLLocationDegrees = 0
var manger:CLLocationManager = CLLocationManager() var manger:CLLocationManager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { @IBOutlet weak var lineX: NSLayoutConstraint!
manger.stopUpdatingLocation() @IBOutlet weak var closeBtn: UIButton!
let location = locations.last @IBAction func closeAction(_ sender: Any) {
lat = location?.coordinate.latitude as! CLLocationDegrees closeBtn.isHidden = true
lng = location?.coordinate.longitude as! CLLocationDegrees listViewBG.isHidden = true
initMapView(lat: lat, lng: lng) IQKeyboardManager.shared.resignFirstResponder()
initSearch() }
@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() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -56,12 +82,25 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -56,12 +82,25 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
} }
searchBr.placeholderStr = "从哪儿发货" searchBr.placeholderStr = "从哪儿发货"
searchBr.cornerRadius = 35/2.0 searchBr.cornerRadius = 35/2.0
searchBr.delegate = self
searchBr.delegateL = self
AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a" AMapServices.shared().apiKey = "ca417b43e3d031db9c29382cc09a174a"
manger.delegate = self manger.delegate = self
manger.startUpdatingLocation() 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) { func initMapView(lat:CLLocationDegrees,lng:CLLocationDegrees) {
AMapServices.shared().enableHTTPS = true AMapServices.shared().enableHTTPS = true
...@@ -98,6 +137,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -98,6 +137,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
var introView:UIView? var introView:UIView?
var titleLbl:UILabel? var titleLbl:UILabel?
var contentLbl:UILabel? var contentLbl:UILabel?
var adrArr:Array<AMapPOI> = []
func onPOISearchDone(_ request: AMapPOISearchBaseRequest!, response: AMapPOISearchResponse!) { func onPOISearchDone(_ request: AMapPOISearchBaseRequest!, response: AMapPOISearchResponse!) {
...@@ -105,6 +145,12 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -105,6 +145,12 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
return return
} }
//解析response获取POI信息,具体解析见 Demo //解析response获取POI信息,具体解析见 Demo
adrArr.removeAll()
response.pois.forEach { (poi) in
adrArr.append(poi)
}
print(adrArr.count)
if introView == nil { if introView == nil {
introView = UIView() introView = UIView()
...@@ -125,11 +171,21 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -125,11 +171,21 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
introView?.addSubview(contentLbl!) introView?.addSubview(contentLbl!)
} }
titleLbl!.text = response.pois.first?.name 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 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 let h = t+c
titleLbl?.snp_updateConstraints({ (make) in titleLbl?.snp_updateConstraints({ (make) in
...@@ -138,9 +194,9 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -138,9 +194,9 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
make.right.equalTo(-10) make.right.equalTo(-10)
make.height.equalTo(t) make.height.equalTo(t)
}) })
contentLbl?.snp_updateConstraints({ (make) in 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.left.equalTo(10)
make.right.equalTo(-10) make.right.equalTo(-10)
make.height.equalTo(c) make.height.equalTo(c)
...@@ -174,7 +230,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -174,7 +230,7 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
}) })
} }
func getStrHeight(str:String,fontSize:CGFloat) -> CGFloat{ func getStrHeight(str:String,fontSize:CGFloat) -> CGFloat{
let lbl = UILabel() let lbl = UILabel()
lbl.text = str lbl.text = str
...@@ -246,5 +302,28 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -246,5 +302,28 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
let bdlat = z * sin(theta) + 0.006 let bdlat = z * sin(theta) + 0.006
return (bdlat,bdlon) 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