ios - 如何将自定义 map 图钉添加到 Apple Watch 上的 map View ?

标签 ios objective-c xcode apple-watch

我开始为 Apple Watch 编写代码,我想知道如何做到这一点:

谢谢!

Screenshot from Apple Interface Guidelines

最佳答案

首先,您需要向 Controller 添加 map View (例如 InterceController.swift )

然后,您可以在 InterfaceController.swift 中调用这些行的awakeWithContext()willActivate()

 let location = CLLocationCoordinate2D(
            latitude: 51.530777,
            longitude: -0.139364
        )

 let span = MKCoordinateSpan(
            latitudeDelta: 0.005,
            longitudeDelta: 0.005
       )

 let region = MKCoordinateRegion(center: location, span: span)

 map.setRegion(region)

 map.addAnnotation(location, withImageNamed: "bee.png", centerOffset: CGPoint(x: 0, y: 0))

关键是调用addAnnotation(location: CLLocationCoordinate2D, withImageNamed name: String!, centerOffset offset: CGPoint)

等效的 Objective-C 代码:

  CLLocationCoordinate2D location = CLLocationCoordinate2DMake(51.530777, -0.139364);

    MKCoordinateSpan span = MKCoordinateSpanMake(0.005, 0.005);

    MKCoordinateRegion region = MKCoordinateRegionMake(location, span);

    [self.map setRegion:region];

    [self.map addAnnotation:location withImageNamed:@"bee.png" centerOffset:CGPointMake(0, 0)];

关于ios - 如何将自定义 map 图钉添加到 Apple Watch 上的 map View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27768904/

相关文章:

ios - 展平 CGPath

ios - NSDateComponents 将 UTC 日期转换为本地时区,搞乱了 "today"nsdate 比较

ios - swift presentViewController 以编程方式在 destinationVC VDL 中找到 nil

ios - 如何添加带约束的 subview ,使 subview 与其父 View 具有相同的框架?

iphone - 更新数据 UITableView

ios - 如何使用 Parse 从 pfobject 获取 pffile

objective-c - 如何更改 Apple 示例代码项目 MoviePlayer

iphone - 已加载 Nib ,但在为 UITableView 的 header 分配自定义 View 时未设置 View 导出

ios - -[NSLayoutConstraint 常量] 断言失败

ios - 如何在 iOS 中管理 viewController