1

The company that I work for has both an iOS and a tvOS version of an app. The app draws a script at the bottom for the user to keep up during a workout, like so: Typical drawing on iOS

This has worked fine for more than a year in any app targeted for iOS. However, when targeting tvOS, with the same drawing code, instead of drawing the way I would expect, the tvOS view has what I'll call "traces" left after drawing each line, as opposed to just having the one line for the current time.

Wrong drawing on tvOS

The drawing code is as follows:

    func addIndicatorLine(_ context:CGContext?, rect: CGRect, start: CGPoint, color: UIColor = UIColor.white) {
    context!.translateBy(x: rect.origin.x, y: rect.height)
    context!.scaleBy(x: 1.0, y: -1.0)

    context!.setLineWidth(1.0)

    context!.setStrokeColor(color.cgColor)
    context!.move(to: CGPoint(x: start.x, y: 0))

    context!.addLine(to: CGPoint(x: start.x, y: rect.size.height - 5))
    context!.strokePath()
    context!.scaleBy(x: 1.0, y: -1.0)
    context!.translateBy(x: -rect.origin.x, y: -rect.height)
}

Am I missing something obvious, or is there something different I have to do for the tvOS version of the drawing code?

pbush25
  • 5,228
  • 2
  • 26
  • 35

1 Answers1

1

So after a couple of days of trying to figure this out, thanks to one answer (https://stackoverflow.com/a/43898524/2820553) that pointed out a line in the docs to me, I needed to give my view a background color, otherwise drawing errors may occur:

If the view’s opaque property is also set to YES, the backgroundColor property of the view must not be nil or drawing errors may occur.

Simply setting the view's background to a clear color solved this issue. Amazing that it didn't manifest in iOS but did in tvOS. Hope this helps anyone else looking for something similar.

pbush25
  • 5,228
  • 2
  • 26
  • 35