我试图在 Google map 上添加一个按钮。我尽我所能,但没有人能帮助我。在 Xcode 预览中,它显示在顶部,但在运行该应用程序后,它位于谷歌地图下方。
Picture after running app
How it looks in XCODE
CODE OF MAP
import UIKit
import GoogleMaps
class HomeViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var scrollView: UIScrollView!
@IBAction func refreshLocation(sender: AnyObject) {
locationManager.startUpdatingLocation()
}
@IBOutlet weak var gMapView: GMSMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
self.scrollView.contentSize=CGSizeMake(320, 700)
let camera = GMSCameraPosition.cameraWithLatitude(15.4989, longitude: 73.8278, zoom: 17)
gMapView.camera = camera
gMapView.myLocationEnabled = true
self.view.addSubview(gMapView)
let marker = GMSMarker()
marker.map = self.gMapView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension HomeViewController {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == CLAuthorizationStatus.AuthorizedAlways {
locationManager.startUpdatingLocation()
gMapView.myLocationEnabled = true
gMapView.settings.myLocationButton = true
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
gMapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
}
}
}
最佳答案
我找到了答案
self.view.bringSubviewToFront(self.view_name)
您需要在父 View 上调用 bringSubviewToFront。
关于ios - 如何在 Google map Xcode 顶部显示 subview 或按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33282331/