NSAnimationContext happening instantaneously - objective-c

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];

Related

Disable roll-out animation for NSOutlineView

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:

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.

Animation of NSImageView not staying in place while changing frame size

I'm using the following code to scale an image slightly larger and then back to its original size:
float width = image.image.size.width;
float newWidth = width * 1.05;
float height = image.image.size.height;
float newHeight = height * 1.05;
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:.7f];
NSAnimationContext.currentContext.completionHandler = ^{
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:.7f];
[[image animator] setFrameSize:NSMakeSize(width, height)];
[NSAnimationContext endGrouping];
};
[[image animator] setFrameSize:NSMakeSize(newWidth, newHeight)];
[NSAnimationContext endGrouping];
The problem is that the image moves slightly up and to the right during the animation instead of staying in place.
How can I keep the image in place during the animation?
Thank you.
It's because the method you're using, -setFrameSize:, does not alter the view's origin, (which is the lower left hand corner on a Mac), so the view literally grows up and to the right. Use -setFrame: with the animator proxy, or use a transform on the view's layer in conjunction with a CABasicAnimation to apply the animation to the view's coordinates linearly.

How to set speed for scrollToEndOfDocument with objective c in mac os

How can I set speed for scrollToEndOfDocument of NSTextView or WebView in Mac os ?
Try this out: I took it from http://forums.pragprog.com/forums/57/topics/588
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:2.0f];
// your code here
[NSAnimationContext endGrouping];

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