手势冲突
功能场景
常用于APP中不同页面切换或者展示历史轨迹等场景。
//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/手势冲突@android.mp4
onPageSelected(int position)
canScroll(View v, boolean checkV, int dx, int x, int y)
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (Math.abs(dx) > 30) {
return super.canScroll(v, checkV, dx, x, y);
} else {
return true;
}
}
复制成功
//mapopen-website-wiki.bj.bcebos.com/demos/iosVideos/手势冲突@2xios.mp4
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
//多手势同时识别
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
复制成功
- (void)panHandler:(UIPanGestureRecognizer *)gesture {
// 当速度大于某个值时触发page切换
if (fabs([gesture velocityInView:self.scrollView].x) > 2300)
{
// -1:左滑,1:右滑
NSInteger direction = fabs([gesture velocityInView:self.scrollView].x) / [gesture velocityInView:self.scrollView].x;
NSInteger index = self.currentIndex - direction;
if (index >= 0 && index <= 2 &&!self.scrollView.isDecelerating)
{
CGFloat width = self.scrollView.frame.size.width * index;
[self.scrollView setContentOffset:CGPointMake(width, 0) animated:YES];
}
}
}
复制成功