2012-04-21 58 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_