CALayer, NSTextView and Scaling

In my application, I want to provide text scaling in a supported NSTextView layer such as Apple TextEdit. I use its analogue of ScalingScrollView . Also I need to create some CALayer overlays on self.window.contentView . Everything is fine until I do [self.window.contentView setWantsLayer:YES] .

Before [setWantsLayer:YES]

enter image description here

After [setWantsLayer:YES]

enter image description here

I have no idea how to fix this problem.

+7
source share
1 answer

I was also looking for a solution to a similar problem. Finally, I found that layer-supported views should be on integrated pixels and not on sub-pixels.

eg. if you dynamically calculate a frame with layer support

  NSMakeRect((self.frame.size.width - 350)/2, (self.frame.size.height - 150)/2, 350, 150) 

you may encounter non-integer values, so you should do something like

  NSMakeRect(floor((self.frame.size.width - 350)/2), floor((self.frame.size.height - 150)/2), 350, 150) 
+6
source

All Articles