2012-04-21 63 views
1

我正在一个项目中,我有一个大的NSMatrixNSImageCells。我需要在他们的单元格中旋转特定的个人Images(或者甚至只是旋转单元格,因为它看起来是一样的)。每个单元格和图像都是40x40的正方形,所以不必进行任何调整,因为我会坚持90度的增量。问题是,因为我使用的是NSImageCells而不是NSImageViews,所以我无法使用setFrameCenterRotation:轻松旋转图像。有谁知道我能做到这一点?旋转一个NSImageCell

回答

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_