• 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
mouseDragged and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mouseDragged and bindings


  • Subject: mouseDragged and bindings
  • From: GW Rodriguez <email@hidden>
  • Date: Sat, 29 Sep 2012 21:52:29 -0700 (PDT)

Problem: a declared property in a NSView subclass doesn't update members bound to it (with bindings) when in a mouseDragged method.

So I have a subclass of NSView that has an ivar that I declare as a property.  In IB I have a NSTextField that I set the binding to the same variable (and I do everything required to add the NSView, use an IBOutlet in the AppDelegate, etc).  I can confirm that the binding is connected because I set the ivar in the initWithFrame method and the NSTextField shows that value.  Also I tried adding a button and connected it to an IBAction method, which worked fine.

But when I click and drag the mouse and attempt to update the ivar with self.ivar within the mouseDragged (which I confirmed that it's being called), it doesn't update the ivar.  I tried also updating it in the mouseUp method and that didn't work either. 

The only thing I can think of is it has something to do with the thread that bindings are in, which must be different that the thread that mouseDragged is in, but I can't confirm that nor know how to deal with it.  Below is my code for my mouseDragged method.  Any help would be greatly appreciated.



-(void) mouseDragged:(NSEvent *)theEvent {
    NSPoint mouseLocation = [theEvent locationInWindow];
    NSPoint convertedLocation = [self convertPoint:mouseLocation fromView:nil];
    CGFloat difference = convertedLocation.y - dragStart;
    
    if([theEvent modifierFlags] & NSCommandKeyMask) // command key
        myDial->rotation = dragDialPos - (difference * 0.5);
    else
        myDial->rotation = dragDialPos - (difference * 3);
    
    // check limits
    if(myDial->rotation>= dialMaxLeft)
        myDial->rotation= dialMaxLeft;
    if(myDial->rotation<= dialMaxRight)
        myDial->rotation= dialMaxRight;
    
    
    // set the dialVal
    // this assumes that the range is 300 from -150 to 150
    self.dialValue = (float) (-(myDial->rotation + 150.0) / 300.0) + 1.0;
        
    [selfsetNeedsDisplay:YES];
}


GW
_______________________________________________

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


  • Prev by Date: Re: Blocks with return type
  • Next by Date: build compatibility for iOS
  • Previous by thread: Re: Blocks with return type
  • Next by thread: build compatibility for iOS
  • Index(es):
    • Date
    • Thread