2009-05-31 7 views

답변

2

인터페이스 빌더로 만든 기존 윈도우를 표시하려면 윈도우 객체에 makeKeyAndOrderFront을 호출하기 만하면됩니다.
프로그래밍 방식으로 새 창을 만들려면 here이라는 대답을 찾으십시오.

0

이벤트를 처리하려면 NSView 또는 NSViewController 하위 클래스에 NSResponder의 관련 메서드를 구현해야합니다. 예를 들어, 당신과 같이, (매우 단순한 방식으로) 마우스 클릭을 처리하기 위해 mouseDown:-mouseUp:을 구현할 수 :

- (void) mouseDown: (NSEvent *) event 
{ 
    if ([event type] != NSLeftMouseDown) 
    { 
     // not the left button, let other things handle it 
     [super mouseDown: event]; 
     return; 
    } 

    NSPoint location = [self convertPoint: [event locationInWindow] fromView: nil]; 
    if (!NSPointInRect(location, self.theRect)) 
    { 
     [super mouseDown: event]; 
     return; 
    } 

    self.hasMouseDown = YES; 
} 

- (void) mouseUp: (NSEvent *) event 
{ 
    if ((!self.hasMouseDown) || ([event type] != NSLeftMouseUp)) 
    { 
     [super mouseUp: event]; 
     return; 
    } 

    NSPoint location = [self convertPoint: [event locationInWindow] fromView: nil]; 
    if (!NSPointInRect(location, self.theRect)) 
    { 
     [super mouseDown: event]; 
     return; 
    } 

    self.hasMouseDown = NO; 

    // mouse went down and up within the target rect, so you can do stuff now 
}