Ser*_*nov 4 iphone uikit uigesturerecognizer ios
我正在使用两个手势识别器UIView.一个是标准的UITapGestureRecognizer,另一个是非常简单的触摸识别器我写道:
@implementation TouchDownGestureRecognizer
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (self.state == UIGestureRecognizerStatePossible) {
self.state = UIGestureRecognizerStateRecognized;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
self.state = UIGestureRecognizerStateFailed;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.state = UIGestureRecognizerStateFailed;
}
@end
Run Code Online (Sandbox Code Playgroud)
只有在我们为包含此方法的两个委托分配委托时,它们才能一起工作:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
这一切都很好,但是当我对该视图执行长按时,触摸识别器触发并触摸识别器不会.对于短的水龙头一切都很好,他们都开火了.
我实现了所有方法UIGestureRecognizerDelegate以返回YES无效.如果我正在添加日志以查看与委托的交互以及在我自己的识别器中,我可以看到,对于短按和长按,调用顺序是相同的 - 除了调用修饰识别器.我做错了什么?
你为什么不直接检查touchUp UILongPressGestureRecognizer?
-(void)selectionDetected:(UILongPressGestureRecognizer*)longPress
{
if(longPress.state==1)
{
//long Press is being held down
}
else if(longPress.state==3)
{
//the touch has been picked up
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2100 次 |
| 最近记录: |