I am implementing the google maps place picker in Swift. The place picker provided by google automatically displays a view controller with a navigation bar. When I select the location or press the back button on the navigation bar, the view controller immediately disappears without any transition. I cannot seem to access the navigation bar at all through the place picker API. How could I dismiss the placepicker view controller with an animation, or perhaps access the navigation bar? I am at a loss. My code brings up the place picker when I press a button:
@IBAction func pickPlace(sender: UIButton) {
if let mapView = self.mapView {
let visibleRegion = mapView.projection.visibleRegion()
let viewport = GMSCoordinateBounds(coordinate: visibleRegion.farLeft, coordinate: visibleRegion.nearRight)
let config = GMSPlacePickerConfig(viewport: viewport)
placePicker = GMSPlacePicker(config: config)
placePicker.pickPlaceWithCallback { (place: GMSPlace?, error: NSError?) -> Void in
if error != nil {
println("Error picking place: \(error!.localizedDescription)")
return
}
if place != nil {
self.userLocationTextField.text = place!.name
println("Place name \(place!.name)")
println("Place address \(place!.formattedAddress)")
println("Place attributions \(place!.attributions)")
let marker = GMSMarker(position: place!.coordinate)
} else {
println("No place selected")
}
}
}
The only way I can get access to the place picker view controller is with the following code:
let topVC = UIApplication.sharedApplication().keyWindow?.rootViewController
But even with that code, I cannot make change the navigation bar or make the view controller dismiss with animation.
I was also facing the same issue and I have solved using below code. I have written below code in place picker button action method
UINavigationBar.appearance().barTintColor = YOURCOLOR
UINavigationBar.appearance().isTranslucent = false
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.