Macos 为什么CATTransferM3dMakeRotation不将(0,0,1)视为绕Z轴旋转?
如果我在Cocoa的应用程序中转换为Macos 为什么CATTransferM3dMakeRotation不将(0,0,1)视为绕Z轴旋转?,macos,cocoa,appkit,catransform3d,Macos,Cocoa,Appkit,Catransform3d,如果我在Cocoa的应用程序中转换为NSView: self.view.layer.transform = CATransform3DMakeRotation(30 * M_PI / 180, 0, 0, 1); 我看到正方形没有绕Z轴旋转,而是旋转,好像向量指向下和外。我要去 self.view.layer.transform = CATransform3DMakeRotation(30 * M_PI / 180, 1, 1, 1); 使其绕Z轴旋转,如上的图片所示 但是,如果我设置了一个
NSView
:
self.view.layer.transform = CATransform3DMakeRotation(30 * M_PI / 180, 0, 0, 1);
我看到正方形没有绕Z轴旋转,而是旋转,好像向量指向下和外。我要去
self.view.layer.transform = CATransform3DMakeRotation(30 * M_PI / 180, 1, 1, 1);
使其绕Z轴旋转,如上的图片所示
但是,如果我设置了一个NSTimer
,然后在update
方法中更新transform
,那么使用
-(void) update:(id) info {
self.view.layer.transform =
CATransform3DMakeRotation(self.degree * M_PI / 180, 0, 0, 1);
self.degree += 10;
}
(这一次,使用
(0,0,1)
)将起作用:它绕Z轴旋转。我想知道为什么(1,1,1)
需要在应用程序的完成启动中使用,但是(0,0,1)
可以在更新方法中使用?结果是需要将视图添加到窗口中。contentView
首先:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.view = [[NSView alloc] initWithFrame:NSMakeRect(100, 100, 200, 200)];
[self.window.contentView addSubview:self.view];
self.view.wantsLayer = YES;
self.view.layer = [CALayer layer];
self.view.layer.backgroundColor = [[NSColor yellowColor] CGColor];
self.view.layer.anchorPoint = CGPointMake(0.5, 0.5);
self.view.layer.transform = CATransform3DMakeRotation(30 * M_PI / 180, 0, 0, 1);
}
另外,行self.view.layer=[CALayer-layer]代码>需要在行的后面self.view.wantsLayer=YES代码>。我不确定为什么会有这些命令,但它的工作原理与预期相符。我还找不到提到此订单要求的文档,但上面的代码有效。当我找到有关为什么需要订单的更多信息时,我将更新答案。这解决了我的应用程序在macOS 10.13上的一个相关问题:定位点始终从中心更改为(0,0)。非常感谢。