我正在做一个项目,其中我有一个很大的NSImageCells NSMatrix。我需要在他们的单元格中旋转特定的单个Images (或者甚至只是旋转单元格本身,因为它看起来是一样的)。每个单元格和图像都是一个40x40的正方形,所以不应该有任何大小调整,因为我将坚持90度的增量。问题是,因为我使用的是NSImageCells而不是NSImageViews,所以不能使用setFrameCenterRotation:轻松地旋转图像。有人知道我是怎么做到这一点的吗?
发布于 2012-04-29 02:02:15
对于任何还在寻找方法的人来说,因为我是用ASOC编写的,所以我最终使用了以下代码:
on rotateImage_byAngle_(startingImage, angle)
set rotated to current application's NSImage's alloc()'s initWithSize_({startingImage's |size|()'s height(), startingImage's |size|()'s |width|()})
rotated's lockFocus()
set transform to current application's NSAffineTransform's transform()
transform's translateXBy_yBy_((rotated's |size|()'s |width|()) / 2, (rotated's |size|()'s height()) / 2)
transform's rotateByDegrees_(angle)
transform's translateXBy_yBy_(-(rotated's |size|()'s height()) / 2, -(rotated's |size|()'s |width|()) / 2)
transform's concat()
startingImage's drawAtPoint_fromRect_operation_fraction_({0, 0}, {{0, 0}, {0, 0}}, current application's NSCompositeCopy, 1)
rotated's unlockFocus()
return rotated
end rotateImage_byAngle_https://stackoverflow.com/questions/10263034
复制相似问题