您问:
基本上,我想知道是否UIGestureRecognizerStateEnded
应该发生UIGestureRecognizer
静止过程触摸,或者此时所有触摸都完成了?
当你得到UIGestureRecognizerStateEnded
时,是的,手势就完成了。但显然,除非您在该点从视图中移除手势识别器,否则如果用户开始一个新手势,则手势识别过程会从UIGestureRecognizerStateBegan
.
此外,你说:
我得到了奇怪的值,translationInView
所以只想在这里问。
您的代码示例表明您正在处理捏合手势,但这并不适用translationInView
,所以我不确定您得到了什么“奇怪的值”。您可以通过设置手势delegate
并实现两个同时手势shouldRecognizeSimultaneouslyWithGestureRecognizer
:
- (void)viewDidLoad
{
[super viewDidLoad];
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self
action:@selector(handlePinch:)];
pinch.delegate = self;
[self.view addGestureRecognizer:pinch];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(handlePan:)];
pan.delegate = self;
[self.view addGestureRecognizer:pan];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]])
return YES;
if ([gestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])
return YES;
return NO;
}
- (void)handlePinch:(UIPinchGestureRecognizer *)gesture
{
CGFloat scale = [gesture scale];
NSLog(@"%s: %@: scale=%.2f", __FUNCTION__, [self stringFromGestureState:gesture.state], scale);
}
- (void)handlePan:(UIPanGestureRecognizer *)gesture
{
CGPoint translation = [gesture translationInView:gesture.view];
NSLog(@"%s: %@: translation=%@", __FUNCTION__, [self stringFromGestureState:gesture.state], NSStringFromCGPoint(translation));
}
上面的代码有效,其中handlePan
返回 pan,handlePinch
返回 pinch,并且translationInView
ofhandlePan
看起来没有异常。也许你可以向我们展示你是如何使用捏合手势和获取translationInView
的,并告诉我们你得到的值有什么奇怪的地方。