web-dev-qa-db-fra.com

Cacao: animation NSView

C'est aussi simple que possible, donc je ne peux pas pour la vie de trouver ce qui ne va pas, j'ai regardé la documentation comme guide mais cela n'a toujours pas fonctionné. J'ai une vue à l'intérieur d'une vue plus grande. Une IBAction est censée effacer la vue intérieure ... c'est tout. Voici ce que j'ai:

NSViewAnimation *theAnim;
NSMutableDictionary *viewDict;

// Create the attributes dictionary for the view.
viewDict = [NSMutableDictionary dictionaryWithCapacity:2];

// Set the target object to be the view.
[viewDict setObject:_innerView forKey:NSViewAnimationTargetKey];

// Set this view to fade out
[viewDict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];

theAnim = [[NSViewAnimation alloc] initWithViewAnimations:@[viewDict]];

// Set some additional attributes for the animation.
[theAnim setDuration:1.0];

// Run the animation.
[theAnim startAnimation];

J'ai vérifié le viewDict et theAnim avec NSLogs et aucun n'est nul. J'ai à peu près copié cela à partir d'un ancien programme que j'avais là où cela fonctionnait, je ne trouve pas ce qui ne va pas maintenant.

J'utilise Xcode 5.1.1

28
Elbimio

L'approche moderne est beaucoup plus simple:

[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
    context.duration = 1;
    view.animator.alphaValue = 0;
}
completionHandler:^{
    view.hidden = YES;
    view.alphaValue = 1;
}];

Si la hiérarchie des vues est basée sur des couches, il suffit en fait de faire:

view.animator.hidden = YES;
69
Ken Thomases