ken*_*ytm 39
为控件事件UIControlEventTouchDownRepeat添加目标操作,并仅在touch tapCount
为2 时执行操作.
Objective-C的:
[button addTarget:self action:@selector(multipleTap:withEvent:)
forControlEvents:UIControlEventTouchDownRepeat];
...
-(IBAction)multipleTap:(id)sender withEvent:(UIEvent*)event {
UITouch* touch = [[event allTouches] anyObject];
if (touch.tapCount == 2) {
// do action.
}
}
Run Code Online (Sandbox Code Playgroud)
正如@Gavin评论的那样,双击一个按钮是一种不同寻常的姿态.在iPhone OS上,双击主要用于可缩放视图以放大/缩小焦点区域.如果您执行手势以执行其他操作,则对于用户可能不直观.
斯威夫特3:
button.addTarget(self, action: #selector(multipleTap(_:event:)), for: UIControlEvents.touchDownRepeat)
Run Code Online (Sandbox Code Playgroud)
然后:
func multipleTap(_ sender: UIButton, event: UIEvent) {
let touch: UITouch = event.allTouches!.first!
if (touch.tapCount == 2) {
// do action.
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11695 次 |
最近记录: |