Question

J'ai un code de base pour ajouter un QTMovieView. Je veux qu'il se fonde, alors j'ajoute une animation sur setAlphaValue. Le seul problème est que cela ne fonctionne pas. La valeur alpha est instantanément définie sur ce à quoi elle était supposée être animée. Si j'essaye d'animer, par exemple setFrame: ça fonctionne bien. Vous trouverez mon code ci-dessous. C’est le 10.5.7 avec le SDK Mac OS X 10.5.

    - (void)addMovie:(NSString *)aFile
    {
            QTMovieView     *aMovieView;
            QTMovie         *aMovie;
            NSRect          contentFrame;

            contentFrame = [[self contentView] frame];

            aMovieView = [[QTMovieView alloc]
                            initWithFrame:contentFrame];
            [aMovieView setWantsLayer:YES];
            [aMovieView setControllerVisible:NO];
            [aMovieView setPreservesAspectRatio:YES];

            aMovie = [[QTMovie alloc]
                            initWithFile:aFile error:nil];

            [aMovieView setMovie:aMovie];

            [aMovieView setAlphaValue:0.4];

            [[self contentView] addSubview:aMovieView];

            [NSAnimationContext beginGrouping];
            [[NSAnimationContext currentContext] setDuration:2.0];
            [[aMovieView animator] setAlphaValue:0.9];
            [NSAnimationContext endGrouping];

    }

Des idées?

Était-ce utile?

La solution 3

J'ai commencé avec QTMovieLayer, mais étant moins puissant (bien entendu) que QTMovieView, il a ouvert une autre boîte de problèmes. La solution consistait à utiliser NSAnimation sur QTMovieView. J'ai un cours NSAnimation qui ressemble un peu à ceci:

AlphaAnimation.h

    #import <Cocoa/Cocoa.h>

    NSString * const AAFadeIn;
    NSString * const AAFadeOut;

    @interface AlphaAnimation : NSAnimation {
            NSView          *animatedObject;
            NSString        *effect;
    }
    - (id)initWithDuration:(NSTimeInterval)duration effect:(NSString *)effect object:(NSView *)object;
    @end

AlphaAnimation.m

    #import "AlphaAnimation.h"

    NSString * const AAFadeIn = @"AAFadeIn";
    NSString * const AAFadeOut = @"AAFadeOut";

    @implementation AlphaAnimation
    - (id)initWithDuration:(NSTimeInterval)aDuration effect:(NSString *)anEffect object:(NSView *)anObject
    {
            self = [super initWithDuration:aDuration animationCurve:0];

            if (self) {
                    animatedObject = anObject;
                    effect = anEffect;
            }

            return self;
    }

    - (void)setCurrentProgress:(NSAnimationProgress)progress
    {
            if ([effect isEqual:AAFadeIn])
                    [animatedObject setAlphaValue:progress];
            else
                    [animatedObject setAlphaValue:1 - progress];
    }
    @end

Ce qui peut alors être utilisé comme ceci:

animation = [[AlphaAnimation alloc] initWithDuration:0.5 effect:AAFadeIn object:movieView];

[animation setAnimationBlockingMode:NSAnimationNonblocking];
[animation startAnimation];

Si vos QTMovieViews sont en plein écran, ce n'est pas très simple, cependant.

scroll top