Distinguishing a single click from a double click in Cocoa on the Mac

后端 未结 5 1080
一向
一向 2021-02-01 21:05

I have a custom NSView (it\'s one of many and they all live inside an NSCollectionView — I don\'t think that\'s relevant, but who knows). When I click

5条回答
  •  旧时难觅i
    2021-02-01 21:29

    If your single-click and double-click operations are really separate and unrelated, you need to use a timer on the first click and wait to see if a double-click is going to happen. That is true on any platform.

    But that introduces an awkward delay in your single-click operation that users typically don't like. So you don't see that approach used very often.

    A better approach is to have your single-click and double-click operations be related and complementary. For example, if you single-click an icon in Finder it is selected (immediately), and if you double-click an icon it is selected and opened (immediately). That is the behavior you should aim for.

    In other words, the consequences of a single-click should be related to your double-click command. That way, you can deal with the effects of the single-click in your double-click handler without having to resort to using a timer.

提交回复
热议问题