1

我正在做一个有大量NSMatrix. NSImageCells我需要Images在他们的单元格中旋转特定的个人(或者甚至只是旋转单元格本身,因为它看起来相同)。每个单元格和图像都是 40x40 的正方形,因此不必调整大小,因为我将坚持 90 度增量。问题是因为我使用NSImageCells而不是NSImageViews,所以我不能setFrameCenterRotation:轻松地旋转图像。有谁知道我怎么能做到这一点?

4

1 回答 1

1

对于仍在寻找方法的任何人,因为我是在 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_
于 2012-04-28T18:02:15.177 回答