Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要为一个按钮实现长按和短按。如何处理它。我使用 longPressGestureRecognizer 实现了长按 .. 现在我不知道如何为短按做同样的事情 .. 就像短按一样,它必须加载 view1 和 long view2。
谢谢你。
通过短按,我假设您的意思是点击按钮。如果您使用的是笔尖,您可以将用于触摸或内部触摸的按钮操作事件连接到 IBAction。如果没有,您可以使用此处详细说明的 addTarget:action:forControlEvents:
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instm/UIControl/addTarget:action:forControlEvents:
如果您决定不使用按钮或不使用 UIControl 方法,则可以将 UITapGestureRecognizer 附加到具有不同目标操作的同一视图。