I have a custom NSView in which the bounds are changed to shrink or enlarge an 
image whenever a magnification event is taking place. Printing out to the 
console shows the bounds origin is changing, but I am not seeing this effect in 
the application’s window. I override -(void)magnifyWithEvent to make this 
happen:

-(void)magnifyWithEvent:(NSEvent *)event {

    CGFloat zoomFactor = [event magnification] + 1.0;

    CGSize newSize = [self bounds].size;

    newSize.width = newSize.width * zoomFactor;
    newSize.height = newSize.height * zoomFactor;

    [self setBoundsSize:newSize];

    CGSize viewFrameSize = [self frame].size;
    CGPoint newOrigin;
    newOrigin.x = (viewFrameSize.width - newSize.width) / 2.0;
    newOrigin.y = (viewFrameSize.height - newSize.height) / 2.0;

    [self setBoundsOrigin:newOrigin];

    [self setNeedsDisplay:YES];

}

Effectively, this should center the bounds in the view’s frame and the image 
should appear centered, but instead I see the image being anchored to the lower 
left corner of the view’s frame. Am I misunderstand how this should work? Do I 
need to investigate a different solution?
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to