1

I have an iOS app with Apple Watch app included. What I do with the solution is showing a trend chart (line graph) which is drawn in iOS app and sent to watch app. I use a WKInterfaceImage instance to show the graph in the Apple Watch app, but it does not look clear. Is there a way to enable zoom for the images in the app so that user can zoom and read/see the details from the chart clearly.

Check the current graph image I have in the watch app,

enter image description here

I am not sure if something like I asked is possible, but if not, could anyone suggest me some better options to implement this better.

2 Answers2

2

There's no way to allow the user to "zoom" in the WatchKit SDK, currently. I would suggest, instead, that you generate your graph images at a size more easily read on the Watch.

bgilham
  • 5,909
  • 1
  • 24
  • 39
0

First I recommend not to generate the UIImage in the iOS app and send it to the Watch Extension because sending an image (ie. NSData) is a lot more data than just sending the coordinates of graph points.

To draw the graph in a clear way I recommend to create a CGContext using UIGraphicsBeginImageContextWithOptions with exactly the size you get from the contentFrame property of WKInterfaceController and a scale of 2 because the Watch display is always Retina. See this example:

    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];

I am using this code with a glance so I need to have specific heights according to glance templates. I am setting the height of the WKInterfaceImage manually to make sure it has the same size like the UIImage, to avoid scaling and thus dithering. This seems to work but it's a bit dirty because of the fixed point numbers.

Note that the 42mm watch gives you a contentFrame width of 156 points, while the 38mm gives you 136 points so you better take these widths from the contentFrame in case it changes in a future WatchOS.

bio
  • 669
  • 4
  • 14