0

I'm fairly new to Cocoa programming, and have a question about control event handling.

I create an 'action' for a button, and get an updated AppDelegate.m to handle this eg.

- (IBAction)seedBtnPressed:(id)sender {
   NSString* myString = @"Hi there";
   [_updateLbl setStringValue:myString];
}

When running this, pressing the 'seed' button does what it should - the label updates. My question is: why have I captured the 'button press event' by default, as I don't see any place where I've specified this. Alternately, how would I capture a mouse-over event with an action? I gather I'd create another action for the button, but am not sure how to specify this to handle 'mouse-over' events only? Sorry if I've used Windows terminology here, I understand Cocoa uses different names for things. Thanks Pete

4

2 に答える 2

1

のマウスオーバー イベントを取得するには、クラスNSViewを使用する必要がありますNSTrackingArea(OS X の比較的新しいバージョンをターゲットにしている場合)。Apple は、これに関する適切なドキュメントをhttp://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/TrackingAreaObjects/TrackingAreaObjects.htmlで入手できます。

指定していませんが、トリガーに関する他のクエリについてseedBtnPressed:-プログラムではなく、ボタンのInterface Builderでアクションを設定しましたか?

于 2012-11-13T07:01:37.437 に答える
1

NSButton クラス (または NSButtonCell クラス) をサブクラス化する必要があります。

- (void)mouseEntered:(NSEvent *)theEvent;
- (void)mouseExited:(NSEvent *)theEvent;

マウスが領域に出入りするときに呼び出される必要があります。トラッキング エリアを再作成する必要がある場合もあります。こちらを参照してください。

- (void)updateTrackingAreas

フェードインとフェードアウトの効果については、たとえばアニメーターとアルファ値で再生しました。

[[self animator]setAlphaValue:0.5]; 
于 2012-11-13T07:02:01.880 に答える