Changing Subview Order Prevents Dragging
Changing Subview Order Prevents Dragging
- Subject: Changing Subview Order Prevents Dragging
- From: Thomas Wetmore <email@hidden>
- Date: Mon, 13 May 2013 22:27:09 -0400
I've been experimenting with a UI for a program that manages many small, draggable views, that can be moved around in the same superview. The following mouse events work well for providing the dragging basics. However, when I drag a view relative to the other views I also want it to end up on top if there is overlap. If I add the three lines of code that are commented out in the mouseDown method, the mouseDragged method stops being called, so the views won't move. On the other hand, if I add those three lines to the mouseUp method, the views move fine, and they transition to the top fine, but only at the very end of the drag, which looks strange as the view pops up through all the other views that were over it.
Can anyone suggest why adding the three lines in mouseDown prevents dragging? Using ARC.
Thanks,
Tom Wetmore
- (void) mouseDown: (NSEvent*) event
{
//NSView* superView = [self superview];
//[self removeFromSuperview];
//[superView addSubview: self];
_startClick = [event locationInWindow];
_startFrame = [self frame];
_dragging = YES;
}
- (void) mouseDragged: (NSEvent*) event
{
if (_dragging) {
NSPoint clickPoint = [event locationInWindow];
NSRect frame = [self frame];
frame.origin.x = _startFrame.origin.x + clickPoint.x - _startClick.x;
frame.origin.y = _startFrame.origin.y + clickPoint.y - _startClick.y;
[self setFrame: frame];
[self setNeedsDisplayInRect: frame];
[self autoscroll: event];
}
}
- (void) mouseUp: (NSEvent*) event
{
_dragging = NO;
//NSView* superView = [self superview];
//[self removeFromSuperview];
//[superView addSubview: self];
}
_______________________________________________
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