适用于iOS的Google Maps SDK:从其他ViewController返回时,地图刷新中的文本/标签(街道名称)

时间:2015-10-22 08:32:14

标签: ios swift google-maps uiviewcontroller

我使用的是使用Swift 1.2(Xcode 6.4)和iOS模拟器的Google Maps SDK for iOS。我的iPad运行与Xcode 7.1和iOS 9.1相同的代码也存在以下问题。

我创建了一个mapView和一个" Press"默认 ViewController 中的按钮。按下按钮后,将显示 ViewControllerB 。如果"返回"按下 ViewControllerB 按钮,应用程序将返回原来的 ViewController

的ViewController:

ViewController

ViewControllerB:

ViewControllerB

我发现从ViewControllerB返回时,mapView中的文本(街道名称)会刷新。

Here is the video of this phenomenon.

我的 ViewController .swift:

class ViewController: UIViewController, GMSMapViewDelegate {

var mapView : GMSMapView!

override func viewDidLoad() {
    super.viewDidLoad()

    println("viewDidLoad")

    mapView = GMSMapView(frame: CGRectMake(0, 100, view.bounds.width, view.bounds.height - 100))

    mapView.camera = GMSCameraPosition.cameraWithLatitude(25.047948, longitude: 121.517405, zoom: 15)

    mapView.mapType = kGMSTypeNormal
    mapView.delegate = self

    view.addSubview(mapView)

    let button = UIButton(frame: CGRectMake(50, 60, 200, 20))
    button.setTitle("Press", forState: UIControlState.Normal)
    button.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
    button.addTarget(self, action: "btnPressed:", forControlEvents: UIControlEvents.TouchUpInside)
    view.addSubview(button)

}

func btnPressed(sender: UIButton) {
    let vcB = ViewControllerB()
    presentViewController(vcB, animated: false, completion: nil)
}

ViewControllerB .swift:

class ViewControllerB: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    let viewB = UIView(frame: view.frame)
    viewB.backgroundColor = UIColor.whiteColor()
    view.addSubview(viewB)

    let colorViewB = UIView(frame: CGRectMake(0, 0, view.bounds.width, 60))
    colorViewB.backgroundColor = UIColor.orangeColor()
    view.addSubview(colorViewB)

    let labelB = UILabel(frame: CGRectMake(100, 30 , 200, 25))
    labelB.text = "ViewControllerB"
    labelB.textColor = UIColor.whiteColor()
    colorViewB.addSubview(labelB)

    let buttonBackB = UIButton(frame: CGRectMake(20, 80, 100, 20))
    buttonBackB.setTitle("Back", forState: UIControlState.Normal)
    buttonBackB.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
    buttonBackB.addTarget(self, action: "btnBackB:", forControlEvents: UIControlEvents.TouchUpInside)
    view.addSubview(buttonBackB)
}

func btnBackB(sender: UIButton) {
    dismissViewControllerAnimated(false, completion: nil)
}

返回 ViewController .swift时,不会调用viewDidLoadmapView = GMSMapView()。所以我不知道为什么地图中的文字是令人耳目一新的,而不是图像部分。

在使用Apple的MKMapView进行测试时,按下"返回"后,街道文字不会刷新。

是否可以防止地图中的文字/标签刷新?

1 个答案:

答案 0 :(得分:0)

动画标签的行为属于GMSVectorMapView私有,是Google Maps SDK for iOS中的私有类。

以下是一些实现不动画标签效果的选项:

  1. 调用执行更新的私有方法来覆盖其行为。我不知道会采用什么方法。

  2. 制作视图的快照并首先显示。在适当的延迟之后,允许动画更新,在隐藏快照的同时显示地图视图。

  3. 使其在导航到地图和从地图导航时不会触发视图控制器转换。如果隐藏和取消隐藏视图,标签不会生成动画。

  4. 您还可以尝试从适用于iOS的Google Maps SDK团队请求此功能。