问题
I need to scale an NSView around it's center. I tried using CATransform3DMakeScale and it worked to scale the view towards it's corner but I couldn't achieve to center it. I tried to set the layers anchor point to .5, .5 but that didn't work. I tried using scaleUnitSquareToSize but I ran into the problem that this seems unresetable without a lot of work.
In the end I need to be able to set the scale of an NSView to something like 0.8 and have it zoom out around it's center and be able to set the scale to 1 again to reset it.
回答1:
Added a frame fix for @fyasar's answer, works for me on MacOS:
CGRect frame = layer.frame;
layer.anchorPoint = CGPointMake(.5, .5);
layer.frame = frame; // Fix the location shift caused from anchor change
回答2:
I also faced with smilar problem.
Please be sure exeute that line before construct CABasicAnimation
.
layer.anchorPoint = CGPointMake(.5, .5);
So, that worked for me.
Good luck
回答3:
If you can require 10.8, then you could call NSScrollView
's function:
- (void)setMagnification:(CGFloat)magnification centeredAtPoint:(NSPoint)point
来源:https://stackoverflow.com/questions/17124457/scale-nsview-centered