2010-08-01 13 views
0

Je cherche à créer un NSWindow se comporter comme la fenêtre de dock: - Apparaît lorsque le curseur de la souris reste à un bord de l'écran - Ne prend pas le focus (l'application ayant le focus le garde) mais reveils événements de la souriscacao: dock comme fenêtre

Une idée sur la façon dont je peux implémenter cela?

Merci d'avance pour votre aide,

Répondre

2

Vous pourriez faire quelque chose avec la valeur alpha de la fenêtre. Utilisez cette sous-classe de NSView comme vue du contenu de votre fenêtre.

#import <Cocoa/Cocoa.h> 

@interface IEFMouseOverView : NSView { 
    BOOL canHide; 
    BOOL canShow; 
} 
- (id)initWithFrame:(NSRect)r; 
@end 


@interface IEFMouseOverView (PrivateMethods) 
- (void)showWindow:(NSTimer *)theTimer; 
- (void)hideWindow:(NSTimer *)theTimer; 
@end 

@implementation IEFMouseOverView 
- (void)awakeFromNib { 
    [[self window] setAcceptsMouseMovedEvents:YES]; 
    [self addTrackingRect:[self bounds] owner:self userData:nil 
      assumeInside:NO]; 
} 
- (id)initWithFrame:(NSRect)r { 
    self = [super initWithFrame:r]; 
    if(self) { 
     NSLog(@"Gutentag"); 
     [[self window] setAcceptsMouseMovedEvents:YES]; 
     [self addTrackingRect:[self bounds] owner:self userData:nil 
       assumeInside:NO]; 
    } 
    return self; 
} 

- (void)mouseEntered:(NSEvent *)ev { 
    canShow = YES; 
    canHide = NO; 
    NSTimer *showTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 
                  target:self 
                 selector:@selector(showWindow:) 
                 userInfo:nil 
                 repeats:YES]; 
    [showTimer fire]; 
} 

- (void)mouseExited:(NSEvent *)ev { 
    canShow = NO; 
    canHide = YES; 
    NSTimer *hideTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 
                  target:self 
                 selector:@selector(hideWindow:) 
                 userInfo:nil 
                 repeats:YES]; 
    [hideTimer fire]; 
} 

- (void)showWindow:(NSTimer *)theTimer { 
    NSWindow *myWindow = [self window]; 
    float originalAlpha = [myWindow alphaValue]; 
    if(originalAlpha >= 1 || canShow == NO) { 
     [theTimer invalidate]; 
     return; 
    } 
    [myWindow setAlphaValue:originalAlpha + 0.1]; 
} 

- (void)hideWindow:(NSTimer *)theTimer { 
    NSWindow *myWindow = [self window]; 
    float originalAlpha = [myWindow alphaValue]; 
    if(originalAlpha <= 0 || canHide == NO) { 
     [theTimer invalidate]; 
     return; 
    } 
    [myWindow setAlphaValue:originalAlpha - 0.1]; 
} 
@end