加载MapView时,我无法放大注释/引脚。
加载MapView时,我希望它开始缩小,然后向注释/引脚放大。 “动画”设置为“true”。我不确定这里出了什么问题。
当地图加载后,它会短暂显示带有图钉的灰色屏幕,然后加载它周围的卫星地图。
谢谢!
使用Swift 3
地图代码:
let embed = new ViddlerEmbed({
videoId: this.active,
target: '#player',
autoplay: 'true',
type: 'video',
width: '100%'
});
针类:
@IBOutlet weak var mapView: MKMapView!
}
override func viewDidLoad() {
super.viewDidLoad()
let distanceSpan:CLLocationDegrees = 300
let redRocks:CLLocationCoordinate2D = CLLocationCoordinate2DMake(39.665496, -105.205438)
let redRocksPin = RedRocksPin(title: "Jerry Garcia 1/2/72", subtitle: "Red Rocks Amphitheatre", coordinate: redRocks)
mapView.addAnnotation(redRocksPin)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(redRocks, distanceSpan, distanceSpan), animated: true)
答案 0 :(得分:1)
在你的类声明中,将这些变量设为:
let distanceSpan:CLLocationDegrees = 300
let redRocks:CLLocationCoordinate2D = CLLocationCoordinate2DMake(39.665496, -105.205438)
在ViewWillAppear中,执行以下操作:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animted)
view.layoutIfNeeded()
let redRocksPin = RedRocksPin(title: "Jerry Garcia 1/2/72", subtitle: "Red Rocks Amphitheatre", coordinate: redRocks)
mapView.addAnnotation(redRocksPin)
}
然后这个:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(redRocks, distanceSpan, distanceSpan), animated: true)
}
这样做会在你的viewwillAppear中,它会绘制mapView,因此你可以添加注释而不会导致崩溃,然后在viewdidappear中,它只会放大你添加的注释。
不确定这是否是最佳方式,但需要尝试。