Resizing NSView with handles
Resizing NSView with handles
- Subject: Resizing NSView with handles
- From: Matt Mashyna <email@hidden>
- Date: Tue, 10 Apr 2007 18:02:52 -0400
I have an NSView subclass that I want to be able to resize by
clicking and dragging handles on the corners. Maybe I'm not going
about it in the right way. I catch the click on the appropriate
handle, change the frame of my view, call setNeedsDisplay and finally
recalculate where the handles should be after dragging.
It works... if I drag slowly. If I move the mouse too fast I seem to
loose my grip on the handle and it stops resizing.
- (void)mouseDragged:(NSEvent *)theEvent {
NSPoint myOrigin = [self frame].origin;
NSRect myOriginalRect = [self frame];
NSRect tempRect = [self frame]; // we'll drag if we're in the
box frame
NSPoint tempPoint = [self convertPoint:[theEvent locationInWindow]
fromView: nil]; // convert the click point to our coord system
...
if(NSPointInRect(tempPoint, URhandle)) // URhandle is an NSRect for
the Upper Right corner
{
NSSize newsize = NSMakeSize(myOriginalRect.size.width + [theEvent
deltaX],
myOriginalRect.size.height - [theEvent deltaY]);
[self setFrameSize: newsize]; // change the frame size
[[self superview] setNeedsDisplayInRect: myOriginalRect]; // tell
it to update
[self setNeedsDisplay: YES]; // tell us to update
[self calculateHandlePositions]; // recalculate our handle
locations
return;
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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