This solution is a little crazy, but it makes logical sense, and has a great visual result. I'm working with a NSLayoutManager
and a couple NSTextContainer
s, laying out text in two columns. Because I'm using multiple text containers (and I'm not sure I want multiple UITextView
), I'm overriding the draw(rect: CGRect)
method of MyDrawingView: UIView
.
The problem is that using self.contentMode = .redraw
still results in some minor stretching on rotation--significant enough to be a deal-breaker.
I noticed that setting contentMode = .left
, or even contentMode = .scaleAspectFit
was close to what I wanted, in terms of pixel-perfect rotation. But obviously, I wasn't getting the draw call I needed.
So--I overrode layoutSubviews()
, switched the contentMode
to .scaleAspectFit
, called super.layoutSubviews()
, and then switched it back. :P
override func layoutSubviews() {
self.contentMode = .scaleAspectFit
super.layoutSubviews()
self.contentMode = .redraw
}
It is...perfect.