开发者

How can I disable the animations in an NSCollectionView

I would like to turn off the 'shuf开发者_高级运维fle' animations that happen when you resize an NSCollectionView. Is this possible?


This works, but it's setting a private instance variable so it may no be ok in the Mac App Store.

[collectionView setValue:@(0) forKey:@"_animationDuration"];


kainjow is correct. adding this:

- (id) animationForKey:(NSString *) key
{
    return nil;
}

to the prototype view subclass (not the collection view!) disables animations


For 10.6, I was able to disable the animation by subclassing NSView, overriding animationForKey: and returning nil. Then make sure you use that view for the prototype's view.


To disable all the collection view's animations in Swift, do this just before the something animatable happens:

NSAnimationContext.current.duration = 0


I was only able to get this to work if I did the following:

1) Subclass the view that the NSCollectionViewItem used as its view. That subclassed view required a CALayer and I set the view subclass as the delegate of the CALayer.

2) Implement the CALayer delegate method so no animation actions should occur:

override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
        return NSNull()
}

3) Finally, in the NSCollectionView data source method:

func collectionView(collectionView: NSCollectionView, itemForRepresentedObjectAtIndexPath indexPath: NSIndexPath) -> NSCollectionViewItem {

    // get a new collection view item
    ....

    // disable animations
    CATransaction.begin()
    CATransaction.setDisableActions(true)

    // populate your cell
    ....

    CATransaction.commit()    
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜