手势冲突
功能场景
常用于APP中不同页面切换或者展示历史轨迹等场景。
//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/手势冲突@android.mp4
1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/newqrcodes/手势冲突@2xanidroid.png
扫码体验
使用产品
Android地图SDK|/index.php?title=androidsdk
>
控件与手势|/index.php?title=androidsdk/guide/interaction/gesture
下载源码
//mapopen-website-wiki.bj.bcebos.com/demos/BaiduMapSDKExample.zip
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
1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/ioscodes/手势冲突@1xios.png
扫码体验
使用产品
iOS地图SDK|/index.php?title=iossdk
>
控件与手势|/index.php?title=iossdk/guide/interaction/gesture
下载源码
//mapopen-website-wiki.bj.bcebos.com/BaiduMapSDKDemo.zip
- (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];
}
}
}
复制成功