Hi I have this bit of code in my project,
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
CGPoint translation = [scrollView.panGestureRecognizer translationInView:scrollView];
if(translation.x < 0.0f) {
// Something
}
}
and it works fine on iPhone, but for some reason on iPad, my CGPoint is always returning (0,0). Any ideas as to why?
I had the same problem, and came up with a nasty workaround, using the velocityInView() method instead. I don't have a real iPad, so I'm suspicious that 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'm using a very handy CGPoint extension you can find right here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With