問題描述
NSViews 上的 CGAffineTransforms (CGAffineTransforms on NSViews)
I am trying to port some iOS code to Mac OS X. I am having trouble porting this though,
CGAffineTransform transform = CGAffineTransformMakeRoatation(-b->GetAngle());
oneView.transform = transform
How can I achieve this? The NSView doesn't have a transform property.
參考解法
方法 1:
You still can use transformations.
Make sure your view is layer-backed by setting setWantsLayer:
on your view to YES
.
Afterwards, you can just set the layer's affine transform:
CGAffineTransform transform = CGAffineTransformMakeRotation(-b->GetAngle());
[[oneView layer] setAffineTransform: transform];
方法 2:
The only way i found to rotate NSView with core animation is
[myView setFrameCenterRotation:angle]
but be carefull using this method. it works correct only if myView is added to a superview. you can track this by overriding method – viewWillMoveToSuperview:
Enjoy)
(by foobar5512、sudo rm -rf、Remizorrr)