我在下面有一个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}
我的代码有什么问题吗?非常感谢
答案 0 :(得分:0)
这是我的代码..它的工作原理。试一试。
- (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);
}