2009-05-31 6 views

答えて

2

既存のウィンドウ(Interface Builderで作成したウィンドウ)を表示する場合は、ウィンドウオブジェクトにmakeKeyAndOrderFrontを呼び出します。
新しいウィンドウをプログラムで作成する場合は、回答はhereです。

0

イベントを処理するには、NSResponderの関連するメソッドをNSViewまたはNSViewControllerサブクラスに実装します。たとえば、マウスクリックを処理するために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 
} 
関連する問題