Cocoa: Animation NSView

C'est aussi simple que possible donc je ne peux pas pour la vie de moi trouver ce qui ne va pas, j'ai regardé à travers la documentation comme un guide mais cela n'a toujours pas fonctionné. J'ai une vue à l'intérieur d'une plus grande vue. Un IBAction est censé disparaître de 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 où cela fonctionnait, Je ne peux pas trouver ce qui ne va pas maintenant.

Je suis sur xcode 5.1.1, merci pour l'aide.

21
demandé sur Elbimio 2014-08-23 01:55:11

1 réponses

L'approche moderne est beaucoup plus facile:

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

Si la hiérarchie de vue est sauvegardée par couche, il suffit de faire:

view.animator.hidden = YES;
54
répondu Ken Thomases 2014-08-23 03:27:19