发生旋转的点受层的
position
和
anchorPoint
属性,请参见
Anchor Points Affect Geometric Manipulations
是的。这些属性的默认值似乎与文档不匹配,至少在MacOS 10.11和您使用的任何版本下都不匹配。
尝试通过添加以下四行来设置它们:
[btnScan setWantsLayer:YES];
CALayer *btnLayer = btnScan.layer;
NSRect frame = btnLayer.frame;
btnLayer.position = NSMakePoint(NSMidX(frame), NSMidY(frame)); // position to centre of frame
btnLayer.anchorPoint = NSMakePoint(0.5, 0.5); // anchor point to centre - specified in unit coordinates
[btnScan.layer addAnimation:animation forKey:@"transform.rotation.z"];
实际上,设置这些属性的顺序并不重要,结果应该是围绕按钮中心点的图像旋转。