
我试过showAnnotations但没有运气.任何人都可以在Swift和Xcode 6.1.1中做到这一点?
这是我的代码:
class VIEwController: UIVIEwController,MKMapVIEwDelegate { @IBOutlet var map: MKMapVIEw! overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() var mapVIEw = map // 1 let point1 = CLLocationCoordinate2D(latitude: 38.915565,longitude: -77.093524) let point2 = CLLocationCoordinate2D(latitude: 38.890693,longitude: -76.933318) //2 let annotation = MKPointAnnotation() annotation.setCoordinate(point1) annotation.Title = "point1" map.addAnnotation(annotation) let annotation2 = MKPointAnnotation() annotation2.setCoordinate(point2) annotation2.Title = "point2" map.addAnnotation(annotation2) //3 // option1: set maprect to cover all annotations,doesn't work var points = [annotation,annotation2] var rect = MKMapRectNull for p in points { let k = MKMapPointForCoordinate(p.coordinate) rect = MKMapRectUnion(rect,MKMapRectMake(k.x,k.y,0.1,0.1)) println("result: x = \(rect.origin.x) y = \(rect.origin.y)") } map.setVisibleMapRect(rect,animated: true) // option 2: using showAnnotations,doesn't work //map.showAnnotations(points,animated: true) } overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated. } } 这就是我目前所得到的:
这是我期望看到的:
谢谢你的帮助.
我终于找到了为什么注释的引脚没有显示在屏幕的可见区域中.我认为MapKit框架的行为与以前的版本略有不同.由于我使用autolayout允许地图扩展到所有设备(iPhone,iPad)的整个屏幕,因此应在mapVIEwDIDFinishLoadingMap中调用setVisibleMapRect或mapVIEw.showAnnotations,而不是在视图控制器的vIEwDIDLoad中调用例如:
func mapVIEwDIDFinishLoadingMap(_ mapVIEw: MKMapVIEw) { // this is where visible maprect should be set mapVIEw.showAnnotations(mapVIEw.annotations,animated: true) } 总结 以上是内存溢出为你收集整理的swift – 无法设置maprect以显示所有注释全部内容,希望文章能够帮你解决swift – 无法设置maprect以显示所有注释所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)