Skip to content

Instantly share code, notes, and snippets.

@kylesluder
Created July 3, 2012 21:45
Show Gist options
  • Select an option

  • Save kylesluder/3043528 to your computer and use it in GitHub Desktop.

Select an option

Save kylesluder/3043528 to your computer and use it in GitHub Desktop.
Cannot animate fade-in of NSView using animator proxy (r.11801145)
@implementation AppDelegate
@synthesize window = _window;
@synthesize box = _box;
@synthesize addButton = _addButton;
@synthesize useDummyAnimationGroup = _useDummyAnimationGroup;
- (void)_prepareForFadeIn;
{
[_box setAlphaValue:0];
[_box setHidden:NO];
}
- (void)addBoxToWindow:(id)sender;
{
// Both of these branches should have the same effect: the view should fade in smoothly.
// On 10.7, it only works the first time if _useDummyAnimationGroup==YES. After that, it works regardless.
// On 10.8, the fade-in never works the first time. Subsequent fade-ins work.
if (_useDummyAnimationGroup) {
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 0;
[self _prepareForFadeIn];
} completionHandler:nil];
} else {
[self _prepareForFadeIn];
}
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 1;
[_box.animator setAlphaValue:1];
} completionHandler:^{
NSLog(@"Fade in complete!");
}];
}
- (void)removeBoxFromWindow:(id)sender;
{
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 1;
[_box.animator setAlphaValue:0];
} completionHandler:^{
[_box setHidden:YES];
NSLog(@"Fade out complete!");
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment