Google Map视图原生控件被statusbar、toolbar遮挡的解决方法咨询
解决Google Map控件被状态栏/工具栏遮挡的问题
Android 端解决方案
- 通过
GoogleMap的setPadding()方法,给地图设置顶部内边距,避开状态栏和工具栏的高度:- 先获取状态栏和工具栏的总高度:
// 获取状态栏高度 val statusBarHeight = resources.getDimensionPixelSize( resources.getIdentifier("status_bar_height", "dimen", "android") ) // 获取工具栏高度 val toolbarHeight = toolbar.height val topPadding = statusBarHeight + toolbarHeight - 给地图设置内边距:
googleMap?.setPadding(0, topPadding, 0, 0)
- 先获取状态栏和工具栏的总高度:
iOS 端解决方案
- 利用
GMSMapView的padding属性,设置顶部偏移量:- 计算状态栏+导航栏的总高度:
let statusBarHeight = UIApplication.shared.statusBarFrame.height let navBarHeight = navigationController?.navigationBar.frame.height ?? 0 let topPadding = statusBarHeight + navBarHeight - 给地图设置内边距:
mapView.padding = UIEdgeInsets(top: topPadding, left: 0, bottom: 0, right: 0)
- 计算状态栏+导航栏的总高度:
内容的提问来源于stack exchange,提问作者user924
相关产品推荐
相关产品推荐

