- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 swift 和 mapkit 开发一个应用程序。除了 mainUser 注释 View 之外,mapView 还有一些注释。我想要的是当用户从另一个 ViewController 选择 UITableViewCell 中的一个单元格时,他应该被带到 mapView ViewController 并选择一个特定的引脚。我通过传递一个名为“fromSegue”的对象来做到这一点。所有这一切都很好,除非用户想要选择自己:选择任何类型的 CustomPointAnnotationView 都没有问题,但在选择 userLocation 时,尚未调用 ViewForAnnotation 函数。
这里是设置 map 区域的函数。这是应该进行注释选择的地方。
func setFPS() {
print("[SFPS] - setFPS")
self.mainUser.setObject(mainUserLocation.latitude, forKey: "latitude")
self.mainUser.setObject(mainUserLocation.longitude, forKey: "longitude")
if self.fromSegue != nil {
print("[SFPS] - setModFPS")
if fromSegue.type == 11 {
print("[SFPS] - type11 - Showing a notif of type 11")
let latititi:Double = fromSegue.latitude as! Double
let longigigi:Double = fromSegue.longitude as! Double
self.mapScope = CLLocationCoordinate2DMake(latititi, longigigi)
var annotJar = pinJar.filter{$0.nickName == self.fromSegue.name}
print("[SFPS] - type11 - ALL RIGHT LETS DO IT")
let annot = annotJar[0]
Map.selectAnnotation(annot,animated: true)
fromSegue = nil
print("[SFPS] - type11 - Over")
} else if fromSegue.type == 21 {
print("[SFPS] - type21 - Showing a notif of type 21")
Map.selectAnnotation(self.Map.userLocation,animated: true)
self.mapScope = mainUserLocation
fromSegue = nil
} else {
print("[SFPS] - no type! problem here")
self.mapScope = CLLocationCoordinate2DMake(mainUserLocation.latitude, mainUserLocation.longitude)
}
} else {
self.mapScope = CLLocationCoordinate2DMake(mainUserLocation.latitude, mainUserLocation.longitude)
}
Map.rotateEnabled = true
let span = MKCoordinateSpanMake(0.001, 0.001)
print("[SFPS] - span made")
let region = MKCoordinateRegionMake(mapScope, span)
print("[SFPS] - region made")
Map.setRegion(region, animated: true)
print("[SFPS] - region is all set - Over")
}
当fromSegue是类型11时,它应该选择一个customPointAnnotationview。这就是控制台中发生的事情:
[SFPS] - setFPS
[SFPS] - setModFPS
[SFPS] - type11 - Showing a notif of type 11
[SFPS] - type11 - ALL RIGHT LETS DO IT
[VFA] - ViewForAnnotation
[VFA] - the annotation: <PING.CustomPointAnnotation: 0x1890d570>. from: Optional(Optional("newParse44"))
[VFA] - of kind random folk
[VFA] - of kind random folk - building...
[DSAV] - didSelectAnnotationView: Optional(Optional("newParse44"))
[DSAV] - guest
[DSAV] - Optional("newParse44") selected
[SFPS] - type11 - Over
[SFPS] - span made
[SFPS] - region made
[SFPS] - region is all set - Over
正在执行函数setFPS(),就在要选择注释的时候,它被创建,然后被选中,然后setFPS()的其余部分被执行。伟大的!这里一切正常。
现在当 fromSegue 的类型为 21 时,应该选择 userLocation 引脚。这是控制台中发生的事情:
[SFPS] - setFPS
[SFPS] - setModFPS
[SFPS] - type21 - Showing a notif of type 21
2015-11-06 07:40:31.116 PING[1272:574013] ERROR: Trying to select an annotation which has not been added
[SFPS] - span made
[SFPS] - region made
[SFPS] - region is all set - Over
所以在这种情况下,还没有添加 userlocation 注释,因为还没有调用 viewForAnnotation(足够早?)。我的问题是为什么?我可以手动调用 viewForAnnotation 吗?
非常感谢您的帮助
最佳答案
在 MKMapView
上 selectAnnotation
之前尝试 setCenterCoordinate
例如:
mapview.setCenterCoordinate(mapview.userLocation.coordinate, animated: false)
mapview.selectAnnotation(mapview.userLocation,animated: true)
更新:
获取用户位置需要一些时间。 MKMapViewDelegate
有 didUpdateUserLocation
,它会在每次位置更新时更新。我们想在第一次触发时获取 userLocation
然后选择它。
在 ViewController
中创建一个 bool
var
。此 var
将用于首次选择注释。我们想忽略 didUpdateUserLocation
的所有其他回调。
class MapViewController: UIViewController {
var didUpdateUserLocation = false
...
...
}
现在实现MKMapViewDelegate
的didUpdateUserLocation
函数。
extension MapViewController : MKMapViewDelegate {
func mapView(mapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation) {
if !didUpdateUserLocation {
mapView.selectAnnotation(mapView.userLocation, animated: true)
didUpdateUserLocation = true
}
}
}
关于ios - 尝试选择尚未添加的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33560980/
我读到的有关 AdSense 的所有内容都表明我需要一个我确实计划获得的网站(博客、域等)。我只是不确定我想要的域名。 但是,我想继续前进,因为来自 Google 的地址验证信可能需要数周时间。 所以
我有一个支持成就的小游戏。游戏尚未发布,但我需要测试成就。我现在可以做,但只是部分做,例如,当我执行游戏中心应用程序时,它似乎总是在沙盒模式下运行,并且该游戏未在“游戏”选项卡中列出。所以,我看不出成
我有一个 MYSQL 表 1,并希望与表 2 创建一个简单的 UNION: SELECT SomeField FROM Table1 UNION SELECT SomeField FROM Table
我希望我的角色可重用且独立。为了可重用,每个角色都按照“单层抽象”范式进行重点工作。这导致了许多小的“原子”角色,在它们之上构建了多层协调角色以提供更复杂的抽象。 为了自包含,每个角色都应该声明它对其
这个脚本有问题:click here .目前它运行良好。但是,如果我通过 w3 验证器运行它,它就不是“有效的”。我也知道这是为什么,因为整个div都在一个链接内。 我想让这个工作完全一样,但也让它得
前言: 我的核心问题与这个非常相似:How can I write a clean Repository without exposing IQueryable to the rest of my a
我正在测试 Xcode 7 的新 UI 测试功能(在 WWDC 2015 视频“UI Testing in Xcode”中介绍)。 启动时,我的应用通过更新其垂直布局约束的值将“登录面板”设置为动画:
我想在 Rails 服务器上运行 Ruby,但某个 gem 不想安装。这个 rails 程序与 ruby 2.0 不兼容,所以我想使用我安装的 ruby 1.9.3,但是我不能再 bundle
大家好, 我的问题:我想为不存在的 IP 地址启动 (tftp) 服务器。该服务器适用于 USB/RNDIS,其 IP 地址本质上仅在存在实际网络流量时才存在 - 但我想“尽早”启动服务器(例如,当
据我所知,document.getElementById('myId') 只会查找文档中已有的 HTML 元素。假设我通过 JS 创建了一个新元素,但我还没有将它附加到文档主体,是否有一种方法可以像我
我刚刚写了这段代码: // Somewhere earlier, the equivalent of this happens. std::set a; std::set b; FillMeUp(a)
我已阅读 here关于 boost:bind 的工作原理,尤其是它 - 除了其他东西 - 生成如下内容: struct unspecified_type { ... some members ..
假设我的本地存储库当前是原点之后的一个提交。假设我在我的本地存储库中提交了一个与源不冲突的更改。如何在不首先从原点 pull/merge 更改的情况下将此更改推送到原点? 最佳答案 好的,所以你因为非
我这里有一个非常奇怪的问题...我继承了一个相当大的 ASP.NET 3.5 Webforms 元素,一个问题是当启动应用程序时,会显示登录页面 - 但没有任何样式。 ... 这是 Login.asp
我试图从 boost::spirit 规则定义的 Action 中引用一个(尚未)未知实例的成员,所以在伪代码中, 代替 double_[ref(rN) = _1]我正在寻找类似的东西 X** ppx
根据 Cast SDK Docs ,要在我需要的 Android 中使用 Cast SDK,Google Play Services Revision 15。 我在我的 SDK 管理器中没有看到 Re
我是一名优秀的程序员,十分优秀!