我在我的应用程序中定义了两个UISwipeGestureRecognizer:
UISwipeGestureRecognizer *swipeLeftVolume = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureVolume:)];
swipeLeftVolume.direction = UISwipeGestureRecognizerDirectionLeft;
[self.playerView addGestureRecognizer:swipeLeftVolume];
UISwipeGestureRecognizer *swipeRightVolume = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureVolume:)];
swipeRightVolume.direction = UISwipeGestureRecognizerDirectionRight;
[self.playerView addGestureRecognizer:swipeRightVolume];在目标方法中,我有三个状态:
UIGestureRecognizerStateBegan
UIGestureRecognizerStateChanged
UIGestureRecognizerStateEnded我注意到只有UIGestureRecognizerStateEnded才被调用。
知道有什么问题吗?我想识别特定UIView上的滑动:
- (void)handleSwipeGestureVolume:(UISwipeGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
NSLog(@"Start");
} else if (sender.state == UIGestureRecognizerStateChanged) {
NSLog(@"Changed");
} else if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"Finish");
}
}发布于 2018-06-05 11:08:48
确保为self.playerView.启用了UserInteraction
发布于 2018-06-05 11:37:42
似乎您在UISwipeGestureRecognizer和UIPanGestureRecognizer之间感到困惑。
UISwipeGestureRecognizer只生成UIGestureRecognizerStateEnded状态,而UIPanGestureRecognizer具有所需的3种状态。
如果您需要同时接收UIGestureRecognizerStateBegan、UIGestureRecognizerStateChanged、UIGestureRecognizerStateEnded,请使用UIPanGestureRecognizer。
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureVolume:)];
[self.playerView addGestureRecognizer:panGesture];发布于 2018-06-05 11:36:21
对于任何手势识别器,必须启用用户交互才能工作。没有它,所有的手势都不会被触发,包括touchBegan:、touchMove:等。
所以你需要让[self.playerView setUserInteractionEnabled:TRUE];
还有一件事,我想让您知道,如果您已经实现了touchBegan:、touchMove:等,那么这个方法将首先被用于手势而不是UIGestureRecognizer shilds。
https://stackoverflow.com/questions/50698255
复制相似问题