1

私が作成しているアプリケーションではNSOpenGLViews、ユーザーがボタンを押したときに特定のフェードインとフェードアウトが表示されるようにしたいと考えています。この目的に向けて、を使用して短いテストアプリを作成しNSViewAnimation、10秒間にわたってビューをフェードアウトしようとしました。コードは、この投稿のコードに密接に基づいています。

NSViewこのコードは、オブジェクトなどから継承された一般的なオブジェクトに対しては完全に機能しますNSBoxが、オブジェクトで使用しようとするとNSOpenGLView、ビューは10秒間何も行われず、その後突然消えます。NSViewAnimation一緒に仕事をするために私がしなければならない余分なことはありますかNSOpenGLView、またはNSViewAnimationこの場合の仕事に適したツールではありませんか?

関連するコード:

// AppDelegate.m
#import "AppDelegate.h"

@implementation AppDelegate
@synthesize theForeground;  // an instance of a the Foreground class - a subclass of NSOpenGLView
@synthesize theBox;
@synthesize theBackground;

//code omitted

- (IBAction)buttonPressed:(id)sender
{
    NSViewAnimation *theAnim;
    NSMutableDictionary * theViewDict;

    theViewDict = [NSMutableDictionary dictionaryWithCapacity:2];
    [theViewDict setObject: theForeground forKey:NSViewAnimationTargetKey];
    [theViewDict setObject:NSViewAnimationFadeOutEffect
                   forKey:NSViewAnimationEffectKey];

    theAnim = [[NSViewAnimation alloc] initWithViewAnimations:  [NSArrayarrayWithObject:theViewDict]];

    [theAnim setDuration:10.0];
    [theAnim setAnimationCurve:NSAnimationEaseInOut];

    [theAnim startAnimation];

    [theAnim release];
}
@end


// Foreground.m

#import "ForegroundView.h"

@implementation ForegroundView

// code omitted
- (void)drawRect:(NSRect)dirtyRect
{
    glClearColor(0, 0, 0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_QUADS);
        glVertex2f(-0.5, -0.5);
        glVertex2f(0.5, -0.5);
        glVertex2f(0.5, 0.5);
        glVertex2f(-0.5, 0.5);
    glEnd();
    glFlush();
}

@end
4

2 に答える 2

1

CAOpenGLLayerOpenGLコンテンツを描画するサブクラスを作成することで、目的の結果を達成することができました。Appleのサンプルコードについては、こちらをご覧ください。その後、フェードインとフェードアウトは次の方法で実現されました。

- (IBAction)buttonPressed:(id)sender
{
    static int isVisible = 1;
    [theGLView.layer setHidden: isVisible];
    isVisible = (isVisible + 1) % 2;
}
于 2012-10-11T02:00:46.633 に答える
0

NSOpenGLViewを、アニメーターでalphaValueを設定したコンテナーNSViewのサブビューとして割り当ててみてください。

[[containerView animator] setAlphaValue: 0.0f];

それは私にとってうまくいきます。

于 2012-10-08T04:39:57.753 に答える