【问题标题】:Is there any possible that make a toolbar on google map?有没有可能在谷歌地图上制作工具栏?
【发布时间】:2015-04-15 02:23:14
【问题描述】:

我曾尝试在谷歌地图上添加 UItoolbar,但地图被工具栏覆盖。

即使我将地图视图添加为子视图,地图视图也不会显示任何内容。在谷歌地图上制作工具栏是不可能的吗?

附加信息:

此视图控制器(GoogleMapController)已被另一个视图控制器推送

Swift 代码:

var camera:GMSCameraPosition = GMSCameraPosition()
var mapView:GMSMapView = GMSMapView()

override func viewDidLoad() {
    super.viewDidLoad()

    let manager = CLLocationManager()
    if CLLocationManager.locationServicesEnabled() {
        manager.startUpdatingLocation()
    }
    if CLLocationManager.authorizationStatus() == .NotDetermined {
        manager.requestAlwaysAuthorization()
    }
   camera = GMSCameraPosition.cameraWithLatitude(lat,longitude:long, zoom:17.5, bearing:30, viewingAngle:40)
   mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)

   var marker = GMSMarker()
   marker.position = CLLocationCoordinate2DMake(lat, long)
   marker.appearAnimation = kGMSMarkerAnimationPop
   marker.title = locationName

   if let mylocation = mapView.myLocation {
       NSLog("User's location: %@", mylocation)
   } else {
       NSLog("User's location is unknown")
   }
   mapView.myLocationEnabled = true
   self.view = mapView
//     self.view.addSubview(mapView)
   let toolbar: UIToolbar = UIToolbar()
   toolbar.frame = CGRectMake(0, self.view.frame.size.height - 48, self.view.frame.size.width, 48)
   toolbar.sizeToFit()
   toolbar.backgroundColor = UIColor.redColor()
   self.view.addSubview(toolbar)
}

【问题讨论】:

    标签: ios google-maps swift uitoolbar


    【解决方案1】:

    我会利用导航控制器来处理这个问题。

    GoogleMapViewController *mapVC = [[GoogleMapViewController alloc] init];
    self.nc = [[UINavigationController alloc] initWithRootViewController:mapvc];
    nc.navigationBar.translucent = NO;
    [nc setToolbarHidden:NO];
    [mapvc addCustomerToolbar];
    

    self.window.rootViewController = self.nc;

    在您的地图视图控制器中 - 您可以将项目设置为导航工具栏 - 或添加自定义视图。

    - (void)addCustomerToolbar {
       CustomView *cv = [[CustomView alloc]init];
        [self.navigationController.toolbar addSubview:progToolbar];
    }
    

    【讨论】:

    • 对不起,这不适合我的情况。感谢您的帮助。 mapview 控制器已由 parentController 与导航控制器推送。
    • 你可以试试 self.hidesBottomBarWhenPushed = NO; self.toolbarHidden = NO;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 2014-10-26
    • 2011-08-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多