私が作成しているアプリケーションでは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