1

The Apple Human Interface Guidelines state that:

An item that provides click-through is one that a user can activate on an inactive window with one click, instead of clicking first to make the window active and then clicking the item. Click-through provides greater efficiency in performing such tasks as closing or resizing inactive windows, and copying or moving files. In many cases, however, click-through could confuse a user who clicks an item unintentionally.

and

Don’t provide click-through for an item or action that:

  • Is potentially harmful and does not allow the user to cancel it (for example, the Delete button in Mail)
  • Is difficult or impossible to cancel (such as the Send button in Mail)
  • Dismisses a dialog without telling the user what action was taken (for example, the Save button in a Save dialog that overwrites an existing file and automatically dismisses the dialog)
  • Removes the user from the current context (for example, selecting a new item in a Finder column can change the target of the Finder window)

What I want to do is that if the user clicks a specific button it will not send its message unless the window is active (for example, the delete message button in Mail). How can I achieve this? If I need to subclass NSButton that's fine.

4

1 に答える 1

1

NSView のドキュメントを参照してください。

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/acceptsFirstMouse :

クリックスルーを有効acceptsFirstMouseにするには、returnをオーバーライドする必要があります。TRUE

デフォルトの動作はクリックスルーではありません:

デフォルトの実装は theEvent を無視し、NO を返します。

コード内、またはコードの基になっているコード内で、このメソッドを既にオーバーライドしている可能性があります。acceptsFirstMouseコード内の の実装を削除してみてください。

于 2011-07-13T16:53:35.297 に答える