UIPanGestureRecognizer 在 iPad 上不起作用?
Posted
技术标签:
【中文标题】UIPanGestureRecognizer 在 iPad 上不起作用?【英文标题】:UIPanGestureRecognizer not working on iPad? 【发布时间】:2015-01-06 07:49:32 【问题描述】:我在下面有一个 UIPanGestureRecognizer 代码:
self.panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panThis:)];
self.panRecognizer.delegate = self;
[self.view addGestureRecognizer:self.panRecognizer];
- (void)panThis:(UIPanGestureRecognizer *)recognizer
switch (recognizer.state)
case UIGestureRecognizerStateBegan:
CGPoint panStartPoint = [recognizer translationInView:self.view];
NSLog(@"Pan Began at %@", NSStringFromCGPoint(panStartPoint));
break;
default:
break;
它可以在 iPhone 上找到,但在 iPad 上,它无法识别平移手势并继续记录
Pan Began at 0, 0
Pan Began at 0, 0
Pan Began at 0, 0
我的代码有什么问题吗?非常感谢
【问题讨论】:
【参考方案1】:这是我的代码.. 它有效。试一试。
- (void)handlePan:(UIPanGestureRecognizer *)recognizer
NSLog(@"handlePan");
//CGPoint p;
switch (recognizer.state)
case UIGestureRecognizerStateBegan:
NSLog(@"UIGestureRecognizerStateBegan");
break;
case UIGestureRecognizerStateEnded:
// All fingers are lifted.
break;
default:
break;
UIView * inView = recognizer.view;
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
///relative to view.
CGPoint center = inView.center;
NSLog(@"handlePan %f %f", center.x, center.y);
【讨论】:
谢谢。我想通了,它应该是velocityInView
,而不是UIGestureRecognizerStateBegan
状态下的translationInView
"velocityInView" 对我帮助很大。以上是关于UIPanGestureRecognizer 在 iPad 上不起作用?的主要内容,如果未能解决你的问题,请参考以下文章
在 UILongPressGestureRecognizer 上启用 UIPanGestureRecognizer
UIPanGestureRecognizer 在视图中使用 UIScrollView
在播放 UIAnimation 时执行 UIPanGestureRecognizer