题
我有一个NSView的在它的一个子类中的一个窗口。视图里面,我把一个NSImage中。
我希望能够通过旋转90度的图像,保持(新)左上角的图像的角部中的视图的左上角。当然,我将不得不旋转图像,然后翻译它把起源回原位。
在碳,我发现CGContextRotateCTM这我想要做什么。但是,我无法找到ObjC正确的电话。 setFrameCenterRotation似乎并没有做任何事情,而在setFrameRotation,我似乎无法找出其中的起源是,这样我就可以approprately翻译。
看来移动。当我调整其大小,将图像窗口(或它的一部分,我似乎有一种奇怪的剪辑问题,因为WEL),当我滚动,它跳跃到一个不同的(而不是总是SAEM)位置。
这是否有道理的人?
感谢
解决方案
我旋转一个应用程序,我的工作和可可在屏幕上的文本(我假设你的意思是可可和不会ObjC在你的问题),这样做是使用NSAffineTransform的方式。
下面是应该让你开始一个段
double rotateDeg = 90;
NSAffineTransform *rotate = [[NSAffineTransform alloc] init];
NSGraphicsContext *context = [NSGraphicsContext currentContext];
[context saveGraphicsState];
[rotate rotateByDegrees:rotateDeg];
[rotate concat];
/* Your drawing code [NSImage drawAtPoint....]for the image goes here
Also, if you need to lock focus when drawing, do it here. */
[rotate release];
[context restoreGraphicsState];
在旋转的数学,因为上面有哪些所做的是,你正在绘制成旋转坐标系可以在这里有点棘手。我的90度的旋转是逆时针旋转。
不隶属于 StackOverflow