2010-08-01 4 views
0

도크 윈도우처럼 행동하는 NSWindow를 만들려고합니다 : - 마우스 커서가 화면의 한쪽 가장자리에 머물러있을 때 나타납니다. - 포커스를 가지고있는 앱이 계속 유지합니다.)하지만 마우스 이벤트를 나타냅니다코코아 : 윈도우 도킹

어떻게 구현할 수 있습니까?

미리 도움 주셔서 감사합니다.

답변

2

당신은 윈도우의 알파 값으로 무엇인가 할 수 있습니다. 이 NSView 서브 클래스를 윈도우의 컨텐츠 뷰로 사용하십시오.

#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 
관련 문제