iOS 10中的地图应用程序现在包含一个标题方向箭头MKUserLocation MKAnnotationView.有什么方法可以MKMapView在我自己的应用程序中添加它吗?
编辑:我很乐意手动执行此操作,但我不确定它是否可行?我可以在地图上添加注释并让它跟随用户的位置,包括动画移动吗?
我在我的iOS应用程序中有一个普通的地图,其中"显示用户位置"已启用 - 这意味着我在地图上有我的正常蓝点,显示我的位置和准确度信息.标注在代码中被禁用.
但我也有定制的MKAnnotationViews,它们在地图上绘制,所有这些都有自定义标注.
这工作正常,但问题是当我的位置在MKAnnotationView的位置时,蓝点(MKUserLocation)拦截触摸,因此MKAnnotationView不会被触及.
如何禁用蓝点上的用户交互,以便MKAnnotationViews而不是蓝点拦截触摸?
这就是我到目前为止所做的事情:
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation;
{
if (annotation == self.mapView.userLocation)
{
[self.mapView viewForAnnotation:annotation].canShowCallout = NO;
return [self.mapView viewForAnnotation:annotation];
} else {
...
}
}
Run Code Online (Sandbox Code Playgroud) 我已MKUserTrackingButton在地图视图中将 Apple 的新功能添加到我的应用程序中。当用户先前已授予使用位置服务的许可(例如CLAuthorizationStatus.authorizedWhenInUse)时,它可以正常工作。
但是,当用户拒绝权限或权限状态未确定时,用户跟踪按钮会变成活动指示器(又名微调器)并且永不停止旋转。
相反,我想像在 Apple Maps 应用程序中一样显示 iOS 权限警报,或者至少显示某种警报,以向用户提示为什么它不起作用。当然,我也希望活动指示器停止并返回默认的“指南针”图标。
不幸的是,MKUserTrackingButton它不是一个 sublass,UIButton所以我不能向它添加任何目标,而且似乎没有 API 来改变按钮的视觉状态。
知道如何做到这一点吗?
我创建了一个地图,右上角有一个用户跟踪按钮。我想知道如何在加载时默认将状态设置为“followWithHeadlights”,以便它跟随用户当前位置,就像在 GPS 上一样?
负载时的当前行为: 按钮当前行为
加载时所需的行为: 按钮所需的行为
代码片段:
func setUserTrackingButton() {
// Mapkit tracking button
let trackingButton: MKUserTrackingBarButtonItem = MKUserTrackingBarButtonItem.init(mapView: mapView)
trackingButton.customView?.tintColor = UIColor(red:0.01, green:0.81, blue:0.37, alpha:1.0)
trackingButton.customView?.frame.size = CGSize(width: 50, height: 50)
let toolBarFrame = CGRect(origin: CGPoint(x: 0, y: 0) , size: CGSize(width: 50, height: 50))
let toolbar = UIToolbar.init(frame: toolBarFrame)
toolbar.barTintColor = UIColor.white
toolbar.isTranslucent = true
let flex: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
toolbar.items = [flex, trackingButton, flex]
let origin = CGPoint(x: self.view.frame.size.width - 85, …Run Code Online (Sandbox Code Playgroud)