如何在Apple Watch中启用缩放图像

时间:2015-05-15 20:13:36

标签: charts zooming apple-watch ios8.3 wkinterfaceimage

我有一个包含Apple Watch应用程序的iOS应用程序。我对该解决方案的处理方式是显示趋势图(折线图),该图表在iOS应用程序中绘制并发送到监视应用程序。我使用WKInterfaceImage实例在Apple Watch应用程序中显示图形,但看起来并不清晰。有没有办法为应用程序中的图像启用缩放功能,以便用户可以清楚地缩放和读取/查看图表中的详细信息。

检查我在监视应用程序中的当前图形图像

enter image description here

我不确定我问的问题是否可能,但如果没有,有人可以建议我一些更好的选择来更好地实现这一点。

2 个答案:

答案 0 :(得分:2)

目前无法让用户“放大”WatchKit SDK。相反,我建议您生成图表图像,其大小更容易在手表上阅读。

答案 1 :(得分:0)

首先我建议不要在iOS应用程序中生成UIImage并将其发送到Watch Extension,因为发送图像(即NSData)比发送图形点的坐标要多得多。 / p>

要以清晰的方式绘制图形,我建议使用UIGraphicsBeginImageContextWithOptions创建一个CGContext,其大小与contentFrame WKInterfaceController CGSize size = self.contentFrame.size; if (size.width > 150) size.height = 99; // 42mm else size.height = 87; // 38mm [self.graphImage setHeight:size.height]; DLog(@"drawing graph into size %@", NSStringFromCGSize(size)); UIGraphicsBeginImageContextWithOptions(size, NO, 2); [graph drawRect:CGRectMake(0, 0, size.width, size.height)]; // draw something UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self.graphImage setImage:image]; 属性的大小完全相同,因为手表显示始终是Retina。见这个例子:

WKInterfaceImage

我正在使用此代码,因此我需要根据扫视模板具有特定的高度。我手动设置contentFrame的高度,以确保它具有与UIImage相同的大小,以避免缩放,从而避免抖动。 这似乎有效但由于固定点数而有点脏。

请注意,42毫米手表的宽度为contentFrame 156点,而38毫米手表则为136点,因此如果未来的WatchOS发生变化,您最好从Sub match_SIC_code_sheet_loop() 'sic code needs to match value in column j or a in sic code sheet, ' 'if not available = met10 works, but probably needs a bit more 'debugging to make it robust. Dim ws As Integer Dim lastrow As Long Dim lastrow_sic As Long Dim output_wb As Workbook Dim SIC_sheet As Worksheet Dim Demand_CAT As String Dim sic_DMA As String Dim i As Integer Dim row As Integer Dim WS_count As Long Dim x As String Dim y As String Set output_wb = Workbooks("DMA_customers_SICTEST.xlsx") 'use thisworkbook instead Set SIC_sheet = Workbooks("DMA_metered_tool_v12_SICTEST.xlsm").Sheets("SIC codes") With SIC_sheet 'count the number of SIC codes to search through lastrow_sic = .Range("j" & .Rows.Count).End(xlUp).row End With With output_wb 'count the no. of sheets in the generated customer workbook WS_count = output_wb.Worksheets.Count End With With output_wb For ws = 1 To WS_count 'loop through each sheet in the customer workbook With output_wb.Sheets(ws) y = output_wb.Sheets(ws).Name lastrow = .Range("a" & .Rows.Count).End(xlUp).row ' number of rows in the 'current customer sheet For i = 2 To lastrow 'data starts in row 2; sic code in column 9 sic_DMA = .Cells(i, 9).Text 'the lookup value With SIC_sheet 'SIC codes start in row 2, if the sic code matches, 'the correct demand category is appointed, if the sic code does not 'match, then MET_10 is given as the default value. For row = 2 To lastrow_sic x = .Cells(row, 3).Text If x = sic_DMA Then Demand_CAT = .Cells(row, 10).Text Exit For Else Demand_CAT = "MET_10" End If Next row output_wb.Sheets(ws).Cells(i, 23).Value = Demand_CAT End With Next i End With Next ws End With output_wb.Save End Sub 获取这些宽度。