NSView and Changing View Bounds...
NSView and Changing View Bounds...
- Subject: NSView and Changing View Bounds...
- From: "Peters, Brandon" <email@hidden>
- Date: Sun, 12 Oct 2014 14:20:45 +0000
- Thread-topic: NSView and Changing View Bounds...
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@hidden)
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:
This email sent to email@hidden