iOS 为 Google 地图上的标记加载自定义信息 window 时应用冻结
iOS app freezes when loading custom info window for marker on Google Maps
我正在尝试在 iOS 应用程序的 Google 地图标记上实现自定义信息 window。 (例如,完成 here and here。)
我已经为它创建了一个 xib 和一个 UIView
class。它被称为 CustomInfoWindow.xib
而 class 是 CustomInfoWindow.swift
。
我的自定义信息 Window 当前为空白,即我还没有向我的 xib 添加任何 UIControl
。我还没有在我的 class 文件中添加任何代码。
CustomInfoWindow.swift
文件基本上如下所示:
import UIKit
class CustomInfoWindow: UIView {}
在我的 ViewController 地图中,我的 markerInfoWindow
方法如下:
func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
let customInfoWindow = NSBundle.mainBundle().loadNibNamed("CustomInfoWindow", owner: self, options: nil)[0] as! CustomInfoWindow
return customInfoWindow
}
当我 运行 代码并单击我的标记之一时,空白 CustomInfoWindow
显示正常。
奇怪的是,当我将任何 UI 元素添加到 Interface Builder 中的 CustomInfoWindow.xib
并再次 运行 我的应用程序时,突然当我点击一个标记时应用程序冻结。 (例如,当我将 UILabel
或 UIImage
添加到 CustomInfoWindow.xib
时。)如果我删除 UI 元素,则空白笔尖会在标记上正常显示。
如果我通过将它作为子视图添加到某个视图控制器上来测试我的笔尖,那么它可以很好地加载我的 UILabel
和 UIImage
。但是,当我在 markerInfoWindow
中使用相同的笔尖时,应用程序会冻结。
可能是什么问题?
更新:
此问题发生在 Google Maps SDK for iOS 的 1.13 版上,结果是 bug on that version.
我也有同样的问题。这是 GoogleMaps 的错误!
冻结版本 1.13.0 中的应用程序。
您可以使用:
pod 'GoogleMaps', '1.12.3'
找到 1.13 的正确解决方法
在子类CustomInfoWindow中添加如下代码
override func didMoveToSuperview() {
superview?.autoresizesSubviews = false;
}
来源:https://code.google.com/p/gmaps-api-issues/issues/detail?id=9525
我正在尝试在 iOS 应用程序的 Google 地图标记上实现自定义信息 window。 (例如,完成 here and here。)
我已经为它创建了一个 xib 和一个 UIView
class。它被称为 CustomInfoWindow.xib
而 class 是 CustomInfoWindow.swift
。
我的自定义信息 Window 当前为空白,即我还没有向我的 xib 添加任何 UIControl
。我还没有在我的 class 文件中添加任何代码。
CustomInfoWindow.swift
文件基本上如下所示:
import UIKit
class CustomInfoWindow: UIView {}
在我的 ViewController 地图中,我的 markerInfoWindow
方法如下:
func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
let customInfoWindow = NSBundle.mainBundle().loadNibNamed("CustomInfoWindow", owner: self, options: nil)[0] as! CustomInfoWindow
return customInfoWindow
}
当我 运行 代码并单击我的标记之一时,空白 CustomInfoWindow
显示正常。
奇怪的是,当我将任何 UI 元素添加到 Interface Builder 中的 CustomInfoWindow.xib
并再次 运行 我的应用程序时,突然当我点击一个标记时应用程序冻结。 (例如,当我将 UILabel
或 UIImage
添加到 CustomInfoWindow.xib
时。)如果我删除 UI 元素,则空白笔尖会在标记上正常显示。
如果我通过将它作为子视图添加到某个视图控制器上来测试我的笔尖,那么它可以很好地加载我的 UILabel
和 UIImage
。但是,当我在 markerInfoWindow
中使用相同的笔尖时,应用程序会冻结。
可能是什么问题?
更新: 此问题发生在 Google Maps SDK for iOS 的 1.13 版上,结果是 bug on that version.
我也有同样的问题。这是 GoogleMaps 的错误! 冻结版本 1.13.0 中的应用程序。
您可以使用:
pod 'GoogleMaps', '1.12.3'
找到 1.13 的正确解决方法
在子类CustomInfoWindow中添加如下代码
override func didMoveToSuperview() {
superview?.autoresizesSubviews = false;
}
来源:https://code.google.com/p/gmaps-api-issues/issues/detail?id=9525