Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CALayer, NSTextView and scaling

In my app I want to provide text scaling in layer backed NSTextView like Apple's TextEdit. I use analogue of it's ScalingScrollView. Also I need to create some CALayer overlays on self.window.contentView. All is ok until I make [self.window.contentView setWantsLayer:YES].

Before [setWantsLayer:YES]

enter image description here

After [setWantsLayer:YES]

enter image description here

I haven't any ideas how to fix this problem.

like image 380
Akki Avatar asked Oct 29 '12 10:10

Akki


1 Answers

I've been searching for the solution to the similar issue, too. Finally, I discovered that layer-backed views must be positioned on integral pixels and must not be positioned on subpixels.

E.g. if you dynamically calculate frame of layer-backed view

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

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

 NSMakeRect(floor((self.frame.size.width - 350)/2), floor((self.frame.size.height - 150)/2), 350, 150)
like image 137
Daniel O'Hara Avatar answered Nov 08 '22 01:11

Daniel O'Hara