从我可以告诉你,你有限的能力来定制用户跟踪按钮。你可以改变颜色。为了让按钮脱离导航栏,您必须将UIToolbar添加到您的mapView中,设置工具栏的框架大小,使其显示在您的首选位置,然后将mkusertrackingbutton作为项目添加到工具栏,并使用灵活的空格以适当的方式添加,以便正确对齐按钮。
这里是我是如何实现它(至今):
func setupUserTrackingButton() {
let trackingButton: MKUserTrackingBarButtonItem = MKUserTrackingBarButtonItem.init(mapView: mapView)
trackingButton.customView?.tintColor = UIColor.black
trackingButton.style = UIBarButtonItemStyle.plain
trackingButton.customView?.size = CGSize(width: 50, height: 50)
let originPoint: CGPoint = CGPoint(x: mapView.width-70,y: mapView.height-85)
let lighterGreyColor: UIColor = UIColor(colorLiteralRed: 125, green: 125, blue: 125, alpha: 1.0)
//need to implement this rounded view in order to get the box to look consistent with the mkusertracking button API
let roundedSquare: UIView = UIView(frame: CGRect(origin: originPoint, size: CGSize(width: 50, height: 50)))
roundedSquare.backgroundColor = lighterGreyColor
roundedSquare.layer.cornerRadius = 5
roundedSquare.layer.masksToBounds = true
let toolBarFrame = CGRect(origin: CGPoint(x: 3, y: 3) , size: CGSize(width: 44, height: 44))
//You may have to subclass toolbar in order to get the right coloring
let toolbar = UIToolbar.init(frame: toolBarFrame)
let flex: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
toolbar.items = [flex, trackingButton, flex]
roundedSquare.addSubview(toolbar)
mapView.addSubview(roundedSquare)
}
否则,你可能有子类的按钮,基本上建立在其他功能,包括核心图形动画,这将是一个工作位。 希望这有助于。