UIPanGestureRecognizer translationInView returns different values ββon iPhone / ipad
Hi I have this code of code in my project,
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
CGPoint translation = [scrollView.panGestureRecognizer translationInView:scrollView];
if(translation.x < 0.0f) {
// Something
}
}
and it works great on iPhone but for some reason on iPad my CGPoint always returns (0,0). Any ideas as to why?
+3
source to share
1 answer
I had the same problem and came up with a nasty workaround using a method instead velocityInView()
. I don't have a real iPad, so I suspect the problem may actually be with the simulator.
Objective-C:
CGPoint velocity = [scrollView.panGestureRecognizer velocityInView: scrollView]; CGPoint translation = CGPointMake(velocity.x * 0.1, velocity.y * 0.1);
Swift:
let translation = scrollView.panGestureRecognizer.velocityInView(self) * 0.1
I am using the very handy CGPoint extension, you can find it right here.
+4
source to share