On Dec 17, 2012, at 2:15 AM, Graham Cox <[email protected]> wrote:

> I have a very simple piece of code that doesn't behave how I expected it to.
> 
> When I drag a CALayer, it does not follow the mouse but snaps to its final 
> location after I exit the loop. I've tried forcing the view to redisplay 
> within the loop, etc but nothing works. How can I do this?
> 
> 
> 
> 
> - (BOOL)    dragItems:(NSSet*) items withEvent:(NSEvent*) event
> {
>    // keeps control and moves the set of items as the mouse is dragged
>    
>    NSUInteger    mask = NSLeftMouseDragged | NSLeftMouseUp | NSLeftMouseDown;
>    BOOL        done = NO;
>    BOOL        dragged = NO;
>    NSPoint        previous, local;
>    
>    previous = [event locationInWindow];
>    
>    while( !done )
>    {
>        event = [self.view.window nextEventMatchingMask:mask untilDate:[NSDate 
> distantFuture] inMode:NSEventTrackingRunLoopMode dequeue:YES];
>        [self.view.window discardEventsMatchingMask:NSAnyEventMask 
> beforeEvent:event];
>        
>        local = [event locationInWindow];
>        
>        NSPoint delta = NSMakePoint( local.x - previous.x, local.y - 
> previous.y );
>        previous = local;
>        
>        // move the layers' positions by <delta>
>        
>        [CATransaction begin];
>        [CATransaction setAnimationDuration:0];
> 
>        for( CALayer* layer in items )
>        {
>            CGPoint pos = layer.position;
>            
>            pos.x += delta.x;
>            pos.y -= delta.y;
>            
>            layer.position = pos;
>        }
>        
>        [CATransaction commit];

What if you call +flush before committing the transaction? CATransaction is 
dependent on the runloop to close its enclosing implicit transactions. This 
might not happen in the event-tracking runloop mode.

(iI only Apple would document what runloop mode(s) CA relies on…)

--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to