Hi,

I'm writing a custom NSCollectionView from scratch, since I can't figure out how to extend NSCollectionView in some specific ways. So, I've got the layout technique I need working, and superficially, things are going smoothly. However, I tried to use NSAnimationContext to set an animation duration, and all I get is a hard freeze. According to Shark, it would appear to be dead locking in a spin lock...


        0.0%    73.5%   CategoryView    start   
        0.0%    73.5%   CategoryView     main   
        0.0%    73.5%   AppKit    NSApplicationMain     
        0.0%    72.7%   AppKit     -[NSApplication run] 
0.0% 72.6% AppKit -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
        0.0%    72.6%   AppKit       _DPSNextEvent      
        0.0%    72.6%   HIToolbox             
BlockUntilNextEventMatchingListInMode     
        0.0%    72.6%   HIToolbox              ReceiveNextEventCommon   
        0.0%    72.6%   HIToolbox               RunCurrentEventLoopInMode       
        0.0%    72.6%   CoreFoundation           CFRunLoopRunInMode     
        0.0%    72.6%   CoreFoundation            CFRunLoopRunSpecific  
        0.0%    72.5%   Foundation                 __NSFireTimer        
0.0% 72.5% AppKit -[NSAnimationManager animationTimerFired:]
        0.0%    72.5%   AppKit               -[NSInFlightAnimation 
advanceToTime:]      
0.0% 72.5% QuartzCore -[CABasicAnimation applyForTime:presentationObject:modelObject:]
        0.0%    72.5%   AppKit                 -[NSView setValue:forKeyPath:]   
0.0% 72.5% Foundation -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] 0.0% 72.5% Foundation -[NSObject(NSKeyValueCoding) setValue:forKey:]
        0.0%    72.5%   Foundation                        
_NSSetUsingKeyValueSetter     
        0.0%    72.5%   AppKit                     -[NSView setFrameOrigin:]    
0.0% 72.5% AppKit -[NSView _postFrameChangeNotification] 0.0% 72.5% Foundation -[NSNotificationCenter postNotificationName:object:] 0.0% 72.5% Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] 0.0% 72.5% CoreFoundation _CFXNotificationPostNotification 0.0% 72.5% CoreFoundation __CFXNotificationPost
        0.0%    72.5%   Foundation                               
_nsnote_callback       
0.0% 72.5% CategoryView -[CategoryView frameSizeChanged:] 0.0% 72.5% CategoryView -[CategoryView updateLayout] 0.0% 72.5% AppKit +[NSAnimationContext endGrouping] 0.0% 72.5% AppKit - [NSAnimationContext(NSInternal) _flushAnimations] 0.0% 66.6% AppKit -[NSAnimationManager startAnimation:forObject:keyPath:targetValue:] 66.6% 66.6% libSystem.B.dylib __spin_lock
        5.9%    5.9%    libSystem.B.dylib                                     
__spin_lock       

My class is "CategoryView" -- it's like an NSCollectionView but with the contents filtered into separate regions by NSPredicates.

Here's my updateLayout method. This is called when the contents of the collection change, or when the view frame size changes. Note that this is very crude code, since I only started writing this custom layout view last night. For example, I've hard coded item size to 128x128.

- (void) updateLayout
{       
        NSSize itemSize = NSMakeSize(128,128),
               layoutSize = [self frame].size;
                
NSPoint origin = NSMakePoint( 0, [self bounds].size.height - itemSize.height );
                
        [NSAnimationContext beginGrouping];
        [[NSAnimationContext currentContext] setDuration: 0.5];

        for ( NSString* category in categoryNames )
        {
                for ( CategoryItemView *item in [self viewsForCategory: 
category] )
                {
                        if ( origin.x + itemSize.width > layoutSize.width )
                        {
                                origin.x = 0;
                                origin.y -= itemSize.height;
                        }

                        [[item animator] setFrameOrigin: origin];
                        origin.x += itemSize.width;
                }
                
                origin.x = 0;
                origin.y -= itemSize.height;
        }
                
        [NSAnimationContext endGrouping]; // freezes here
}

Any ideas? I'm a little new to animation in Cocoa, so if I'm doing something wildly wrong I'm all ears. The docs for NSAnimationContext describe pretty much exactly the usage scenario I'm in...

Note, the above code works *without* NSAnimationContext. I just want to be able to simply set the animation duration to be nice and quick.


shamyl zakariya
        - squamous and rugose



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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

This email sent to arch...@mail-archive.com

Reply via email to