2

我的旋转有问题NSView

假设我有NSImageView这样的:

sampleImage = [[NSImageView alloc] initWithFrame:CGRectMake(50,50,50,50)];
sampleImage.image = [NSImage imageNamed:@"image"];
[self.view addSubview:sampleImage];

看起来像这样:

照片 1

现在我想将此图像旋转 60 度。我已经尝试了几个解决这个问题的方法,但没有一个给我满意的结果。

我试过:

[sampleImage rotateByAngle:60];

结果如下所示:

照片 2

[sampleImage setFrameCenterRotation:60];

结果:

照片 3

使用 AffineTransform 和图层(我也wantsLayer = YES 为超级视图设置了)根本不会旋转图像:

sampleImage.wantsLayer = YES;
sampleImage.layer.affineTransform = CGAffineTransformMakeRotation(60);

旋转CATransform3DMakeRotation也不起作用:

sampleImage.transform = CATransform3DMakeRotation(GLKMathRadiansToDegrees((float) -marker.rotation), 0, 0, 1.0);

在 OSX 中旋转图像的正确方法是什么?在 IOS 上它是小菜一碟:应用适当的 affineTransform 工作就像一个魅力 - 看起来 OSX 上的 Cocoa 不太愿意旋转视图。

4

0 回答 0