首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >旋转NSImageCell

旋转NSImageCell
EN

Stack Overflow用户
提问于 2012-04-22 05:08:11
回答 1查看 241关注 0票数 1

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-29 02:02:15

对于任何还在寻找方法的人来说,因为我是用ASOC编写的,所以我最终使用了以下代码:

代码语言:javascript
复制
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_
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10263034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档