Rotating NSImageView cause the NSImageView to scal

2019-06-07 05:15发布

问题:

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];