我正在尝试将一个应用程序迁移到iOS 11,几天来我被一个又一个丑陋的UI错误所困扰。这一次: MKMapView。我有一堆按钮,我把它们固定在安全区域布局指南上,一切都很好--除了MKMapView。
它完全忽略了安全区域,因此指南针和法律按钮隐藏在条形图或我自己的UI元素下面。为了验证,我创建了一个只有一个普通UIViewController的新项目。然后,我添加了一个MKMapView并配置了自定义的"additionalSafeAreaInsets“,这些实际上被完全忽略了。
更糟糕的是,即使只有MKMapView,iPhone X上的合法标签看起来也大错特错。
there :有什么方法可以嵌入合法标签和指南针,使其不被自定义视图隐藏?
发布于 2018-06-06 04:23:51
正确的方法是设置包含MKMapView
的视图控制器的additionalSafeAreaInsets
。这样做将允许您根据需要调整指南针和“合法”标签,以适应地图顶部的自定义视图。
发布于 2018-06-14 06:28:19
唯一对我有效的解决方案
下面是一个例子
@IBOutlet weak var mapView: MKMapView! {
didSet {
let userTrackingButton = MKUserTrackingButton(mapView: mapView)
userTrackingButton.layer.position = CGPoint(x: 100, y: 100)
userTrackingButton.backgroundColor = UIColor.white
let compassButton = MKCompassButton(mapView: mapView)
compassButton.layer.position = CGPoint(x: 100, y: 150)
compassButton.compassVisibility = .adaptive
mapView.delegate = self
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.follow, animated: true)
mapView.addSubview(userTrackingButton)
mapView.addSubview(compassButton)
}
}
发布于 2018-12-02 23:40:23
在我自己的一个项目中,看起来interface builder有一个解决方案:
在地图视图中,选择“保留Superview页边距”和“安全区域相对页边距”,法律+罗盘将被正确定位。
https://stackoverflow.com/questions/47452115
复制相似问题