我正在尝试制作一个Apple Watch应用程序(扩展名),该应用程序以类似于Apple Maps应用程序的方式显示地图。我希望能够显示地图的一部分,然后能够使用数字表冠进行缩放,并使用手势进行滚动。

我认为使用Watch OS2应该可以做到这一点,但是我还没有弄清楚要使用哪些API。

目前在平台上可以吗?

更新:我不认为我可以使用WKInterfaceMap,因为我想生成自己的地图,而不要使用现有的地图。

最佳答案

仅在内部Watch OS2 API中,WKInterfacePicker可以访问Digit Crown
因此,我们不能直接将Digit Crown用于WKInterfaceMap,但可以通过使用WKInterfacePicker使用它


将WKInterfaceMap和WKInterfacePicker放入组中
设置WKInterfacePicker的大小宽度固定= 2高度固定= 2
我们不能将大小设置为零

api - 在Apple Watch上显示可缩放,可滚动的图像-LMLPHP
注意:不要隐藏WKInterfacePicker一段时间,因为隐藏会辞职
为Picker Controller添加以下代码



  class InterfaceController: WKInterfaceController{
         @IBOutlet var mapView : WKInterfaceMap!
         @IBOutlet var tempPicker:WKInterfacePicker!

         var zoomArray:[Double] = [1.0,0.98,0.96,0.94,0.92,0.90,0.88,0.86,0.84,0.82,0.80,0.78,0.76,0.74,0.72,0.70,0.68,0.66,0.64,0.62,0.60,0.58,0.56,0.54,0.52,0.50,0.48,0.46,0.44,0.42,0.40,0.38,0.36,0.34,0.32,0.30,0.28,0.26,0.24,0.22,0.20,0.18,0.16,0.14,0.12,0.10,0.09,0.08,0.07,0.06,0.05,0.04,0.03,0.02,0.01,0.009,0.008,0.007,0.006,0.005,0.004,0.003,0.002,0.001]

          override func awakeWithContext(context: AnyObject?) {
                    super.awakeWithContext(context)

                    let pickerItems: [WKPickerItem] = zoomArray.map {
                        let pickerItem = WKPickerItem()
                        pickerItem.caption = String($0)
                        pickerItem.title = String($0)
                       return pickerItem
                     }

                   self.tempPicker.setItems(pickerItems)
                   self.tempPicker.setSelectedItemIndex(25)

                   let span = MKCoordinateSpanMake(zoomArray[25], zoomArray[25])
                  let lc = watchDelegate.locationModel.myLocation ?? CLLocationCoordinate2D.init(latitude: 0.0, longitude: 0.0)//watchDelegate.locationModel.myLocation is current user Location
                  let region = MKCoordinateRegionMake(lc, span)
                  self.mapView.setRegion(region)
           }

       @IBAction func pickerChanged(value: Int) {

         let lc = watchDelegate.locationModel.myLocation ?? CLLocationCoordinate2D.init(latitude: 0.0, longitude: 0.0)
         let span = MKCoordinateSpanMake(zoomArray[value], zoomArray[value])
         let region = MKCoordinateRegionMake(lc,
                                        span)
         self.mapView.setRegion(region)

         self.tempPicker.focus()
      }
 }



将@IBAction和IBOutlet连接到WKInterfacePicker和WKInterfaceMap

08-03 23:03