Disable roll-out animation for NSOutlineView - objective-c

Is there a way to stop the roll-out animation for an NSOutlineView. By 'roll-out' I mean the animation that happens when an item is expanded/collapsed, and the children slide down/up.

Create a subclass of NSOutlineView and suppress animation:
-(void) expandItem:(id)item expandChildren:(BOOL)expandChildren
{
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.0];
[super expandItem:item expandChildren:expandChildren];
[NSAnimationContext endGrouping];
}
Other methods are:
– expandItem:
– expandItem:expandChildren:
– collapseItem:
– collapseItem:collapseChildren:

Related

NSWindow animate size change new subview with auto layout

I have a NSWindowController containing several NSViewController. The windowController displays the view of the first viewController as a subView of the main window.
On a button click the windowController adds the next viewControllers view as subView, adds some layout constraints and animates them so that the first view moves out and the next view moves in. After the animation the first view is removed from its superView.
[nextController setLeftLayoutConstraint:nextLeft];
// ^^^^^^^^^^^^^^^^^^^^^^^ custom category'd property
[containerView addSubview:nextView];
[containerView addConstraints:#[nextWidth, nextHeight, nextTop, nextLeft]];
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
[context setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[context setDuration:0.5];
[[nextLeft animator] setConstant:[self leftOffset]];
[[[[self currentViewController] view] animator] setAlphaValue:-0.25]; // negative alpha to shift the timing
[[[[self currentViewController] leftLayoutConstraint] animator] setConstant:-NSWidth(containerView.frame)];
// ^^^^^^^^^^^^^^^^^^^^ custom category'd property
} completionHandler:^{
[[[self currentViewController] view] setAlphaValue:1.0];
[[[self currentViewController] view] removeFromSuperview];
[[self currentViewController] removeFromParentViewController];
_currentViewController = nextController;
}];
Now the second view is much taller than the first so it changes the windows hight as well.
Unfortunately this window frame change is not animated and the window pops ugly in the right size.
I tried getting the next views hight first to then animate all constraints or something like this. Unfortunately the views are not in the correct size before the animation is done.
Is there any way to animate the window change as well?

Mavericks issue: CAKeyframeAnimation on window does not animate

I am working on adapting my app to Mavericks since I have been developing it for 10.8. So far I have found various issues which I can't seem to be able to solve. One of them has to do with NSPopover-like animations.
I have a window which I animate in this way:
_zoomWindow.alphaValue = 0;
[_zoomWindow orderFront: self];
// Configure bouncing animation
CAKeyframeAnimation* frameAnim = [CAKeyframeAnimation animation];
[frameAnim setTimingFunction: [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]];
[frameAnim setValues: #[[NSValue valueWithRect: startFrame], [NSValue valueWithRect: overshootFrame], [NSValue valueWithRect: endFrame]]];
[frameAnim setDuration: duration];
[frameAnim setDelegate: self];
[_zoomWindow setAnimations: #{#"frame": frameAnim}];
// Configure alpha animation
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration: duration];
[[_zoomWindow animator] setAlphaValue: 1.0];
[[_zoomWindow animator] setFrame: endFrame display: YES];
[NSAnimationContext endGrouping];
This works beautifully on 10.8! But it just doesn't do anything on 10.9. Am I missing something here?
I figured it out. The result was that it didn't show anything while suposedly animating, so at first I thought it wasn't animating at all. As it turns out, the problem was in another part of my code completely: the window that I was animating had the content view subclassed by me, and that view was doing some custom drawing. The real problem was that the view wasn't drawing anything on 10.9, even though it was drawing on 10.8... Once I fixed the drawing issue, the animation worked perfectly.

Prevent the user from manually scrolling NSScrollview?

I am using an NSScrollview to scroll programatically. I have hidden the horizental and vertical scrollers but the user is still able to scroll using the mouse wheel.I want to prevent thismanual scrolling.
This is how I am doing the automatic scrolling
- (IBAction)scrollToMidAnimated:(id)sender
{
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:2.0];
NSClipView* clipView = [self.scrollView contentView];
NSPoint newOrigin = [clipView bounds].origin;
newOrigin.y = [self.scrollView contentView].frame.size.height/2.0;
[[clipView animator] setBoundsOrigin:newOrigin];
[NSAnimationContext endGrouping];
}
It works perfectly but I want to prevent the user from manual scrolling(I only want to scroll programatically).Is there any way to do that?
Try like this create custom scrollview class and then include below piece of code:-
- (void)scrollWheel:(NSEvent *)theEvent
{
[[self nextResponder] scrollWheel:theEvent];
}
Finally got the solution.I subclassed NSScrollView and overrided its method scrollwheel and left it empty.
- (void)scrollWheel:(NSEvent *)theEvent
{
// Do nothing
}
if you did hide the scrollers and prevent user scrolling, are you sure you want NSScrollView at all in the first place? Just use NSClipView and animate just like you are doing. No need to subclass and override scrollWheel:. Its a little more cleaner and concise.

OS X 10.7 Animation Did stop selector

I am trying to figure out how to set a call back for when my nsview animator stops. Anyone know how to do this.
NSRect frame = blob.frame;
frame.origin.x = animationStopX;
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:timeToDisappear];
[[blob animator] setFrame:frame];
[NSAnimationContext endGrouping];
On 10.8, NSAnimationContext has completionHandler property which you can use with a block.
You can set delegate for frameOrigin animation.
CAAnimation *moveAnimation = [[blob animationForKey:#"frameOrigin"] copy];
moveAnimation.delegate = self;
[blob setAnimations:[NSDictionary dictionaryWithObject:moveAnimation forKey:#"frameOrigin"]];
[moveAnimation release];
And override end animation delegate method
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag

NSAnimationContext happening instantaneously

I have a simple animation:
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:15.0];
[tweetsView setFrame:finalRect];
[NSAnimationContext endGrouping];
But it doesn't animate. The result is applied immediately. What am I missing?
Thanks
setFrame call must go to view's animator proxy:
[[tweetsView animator] setFrame:finalRect];