是否有任何类型的触摸事件的通用处理程序之类的东西?当发生任何类型的交互时调用的方法,其中有关作为参数传递的触摸事件的信息。
问问题
240 次
1 回答
1
您将要遵守UIGestureRecognizerDelegate 协议,即以下两种方法:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
在这些方法中,您可以检查手势识别器对象以查看它是否是您正在寻找的手势类型,并指定手势是否应该开始或接收触摸。
编辑:要检测手势的结束,您将拥有如下内容:
// in viewDidLoad or in initialization of your view controller:
_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestureRecognizer:)];
[self addGestureRecognizer:_panGestureRecognizer];
[_panGestureRecognizer setDelegate:self];
- (void)handlePanGestureRecognizer:(UIPanGestureRecognizer *)gesture {
UIGestureRecognizerState state = [gesture state];
if (state == UIGestureRecognizerStateEnded) {
// gesture ended here
}
}
于 2013-07-10T18:01:31.777 回答