Reputation: 137
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?
Upvotes: 4
Views: 1076
Reputation: 1268
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.
Upvotes: 4