Rotating NSImageView cause the NSImageView to scale

岁酱吖の 提交于 2019-12-08 08:43:11

问题


I am using the following code to rotate a NSImageView (actually three stacked on top of each other) the rotation works fine, but the image scales up and down when it rotates. why? and how can i fix it?

- (void)UpdateRotate:(CGPoint)mouseLoc{

mouseLoc.y = mouseLoc.y - 200;

CGPoint playerMid = CGPointMake(prect.xPos, prect.yPos);

x = mouseLoc.x - playerMid.x;
y = mouseLoc.y - playerMid.y;
double priorResult = rot;
rot = atan2(y,x) * 180 / PI;

[image rotateByAngle:-priorResult];
[image rotateByAngle:rot];
[image setNeedsDisplay:YES];
[WeaponImage rotateByAngle:-priorResult];
[WeaponImage rotateByAngle:rot];
[WeaponImage setNeedsDisplay:YES];
[ShieldImage rotateByAngle:-priorResult];
[ShieldImage rotateByAngle:rot];
[ShieldImage setNeedsDisplay:YES];
}

Solved!

instead of rotating each NSImageView i just rotated the whole NSView containing all the ImageViews =D

Code:

[self setFrameCenterRotation:-priorResult];
[self setFrameCenterRotation:rot];
[self setNeedsDisplay:YES];

回答1:


Perhaps call - (void)setImageScaling:(NSImageScaling)newScaling; with NSImageScaleNone to turn off scaling?




回答2:


Use:

[anImageView setFrameCenterRotation:angleInDegrees];


来源:https://stackoverflow.com/questions/4640723/rotating-nsimageview-cause-the-nsimageview-to-scale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!