• 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
Re: Need HELP - Dragging a view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need HELP - Dragging a view


  • Subject: Re: Need HELP - Dragging a view
  • From: "" <email@hidden>
  • Date: Thu, 2 Mar 2006 04:00:35 -0500 (EST)

 Thanks  for the answer.

I tried also to draw a rectangle and to drag it around (using Cocoa). Same result: slow.

My code follows this kind of reasoning:

In -mouseDown:(NSEvent *)theEvent of the superview I check if the mouse
click point lies in the rectangle. If so I store its coordinates.

In -mouseDragged:(NSEvent *)theEvent I offset the rectangle and I refresh the
superview.

Here it is a code sample:

- (void)mouseDown:(NSEvent *)theEvent
{
        NSPoint event_location = [theEvent locationInWindow];
        NSPoint local_point = [self convertPoint:event_location fromView:nil];

        if ([self mouse:local_point inRect:_frame1]) {
              orgPoint = local_point;
              dragging = YES;
        }
}

// Mouse dragging.
- (void)mouseDragged:(NSEvent *)theEvent
{
         if (dragging) {
                 NSPoint event_location = [theEvent locationInWindow];
                 NSPoint local_point = [self convertPoint:event_location fromView:nil];

                _frame1 = NSOffsetRect(_frame1, local_point.x - orgPoint.x, local_point.y - orgPoint.y);
               orgPoint = local_point;
               [self setNeedsDisplay:YES]; // Graphics update
          }
}

// Set the dragging flag to NO: we are no more dragging!
- (void)mouseUp:(NSEvent *)theEvent
{
      if (dragging) {
            dragging = NO;
      }
}



 --- On Thu 03/02, Scott Anguish < email@hidden > wrote:
From: Scott Anguish [mailto: email@hidden]
To: email@hidden
     Cc: email@hidden
Date: Thu, 2 Mar 2006 03:05:56 -0500
Subject: Re: Need HELP - Dragging a view

it's best not to rely on views as your application's child objects  like this.  In fact the Cocoa performance docs recommend against it  explicitly.this is probably terribly slow because you're dragging the same view  that is getting the events..On Mar 2, 2006, at 2:34 AM, ""    wrote:>> Hello!>> I did a little app with a view that holds a subview.> My problem is to drag that subview around in its superview,> but it is SLOW!>> I tried also to draw both the subview and the superview contents> using Quartz (in the -drawRect: methods), but with no success.>> Any suggestion?>> Thanks for any answer.> David.>> My code in the subview implementation file>> - (void)mouseDown:(NSEvent *)theEvent> {>         	NSPoint event_location = [theEvent locationInWindow];> 	NSPoint local_point = [self convertPoint:event_location  > fromView:nil];> 	> 	dx = local_point.x;> 	dy = local_point.y;> }>> - (void)mouseDragged:(NSEvent *)theEvent> {> 	MainView *mainView;> 	mainView = (MainView *)[self

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Need HELP - Dragging a view
      • From: Keith Wilson <email@hidden>
  • Prev by Date: Re: How to get the values entered in pagesettings panel in a Document based Application
  • Next by Date: Re: NSBitmapImageRep getPixel and color Spaces
  • Previous by thread: Need HELP - Dragging a view
  • Next by thread: Re: Need HELP - Dragging a view
  • Index(es):
    • Date
    • Thread