我试图在Google地图上添加一个按钮.我尽我所能,但没有任何人可以帮助我..在
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)
您需要在父视图上调用bringSubviewToFront.