• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Changing Subview Order Prevents Dragging
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Changing Subview Order Prevents Dragging
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Window positioning and screen resizing
  • Next by Date: Re: Changing Subview Order Prevents Dragging
  • Previous by thread: Re: Window positioning and screen resizing
  • Next by thread: Re: Changing Subview Order Prevents Dragging
  • Index(es):
    • Date
    • Thread