gpt4 book ai didi

ios - 使 GoogleMap 在使用 MMDrawerController 时保持其位置

转载 作者:行者123 更新时间:2023-12-01 19:04:59 25 4
gpt4 key购买 nike

我在我的项目中使用 MMDrawerController 和 GoogleMap 的 api。
我想要一个带有两个左右滑出导航栏的 GoogleMap View ,并且它们仅在我分别从左右滑动 20px 内时出现。
一切都按预期工作,除了:
当我在具有属性的mapView的benzel(20px)上滑动时:

[drawerController
setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeBezelPanningCenterView];

它还使 googlemap 的 View 也响应平移手势,并使其滑开。

关闭手势
[drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

工作正常
[drawerController 
setCenterHiddenInteractionMode:MMDrawerOpenCenterInteractionModeNone];

滑出抽屉时如何使 map 保持静止?

谢谢 !

----------------

回答 : (stackoverflow 不允许我回答我的问题,因为它是在不到 8 小时前发布的)

我找到了解决方案。归功于 https://github.com/kcharwood .我只是修改了他的一些代码。
- (void)viewDidLoad
{
self.view = _mapView;

[[self.view.subviews[0] gestureRecognizers] enumerateObjectsUsingBlock:^(UIGestureRecognizer * gesture, NSUInteger idx, BOOL *stop){
[gesture setDelegate:self];
}];
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
CGPoint location = [touch locationInView:self.view];
CGRect boundingRect = self.view.bounds;
if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]){
boundingRect.origin.x+=20;
boundingRect.size.width-=40;
}
return CGRectContainsPoint(boundingRect, location);
}


-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}

注意:坚持 gestureRecognizer: shouldRecognizeSimultaneouslyWithGestureRecognizer:将可用。

20和40表示 View 的左右区域。如果平移手势在这些区域内的起始位置, map 将不会移动。
如果你只想剩下:将它们更改为 20 和 20。
如果您希望它们更小,例如 10 和 20,请记住更改 CGFloat const MMDrawerBezelRange = 20.0f; (默认值)在 MMDrawerController.m 中为 10。

最佳答案

通过简单地将 UIGestureRecognizers 捆绑在一起,我找到了一个更优雅的解决方案,以便抽屉的平移手势取代 map 的平移手势:

// walk the drawer controller's gesture recognizers
UIGestureRecognizer *drawerPanGestureRecognizer = nil;
for (UIGestureRecognizer *gestureRecognizer in drawerController.view.gestureRecognizers) {
// grab the pan gesture recognizer
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
drawerPanGestureRecognizer = gestureRecognizer;
break;
}
}

// walk the map view's gesture recognizers
for (UIGestureRecognizer *gestureRecognizer in ((UIView *)mapView.subviews[0]).gestureRecognizers) {
// to find the pan gesture recognizer
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
// panning the drawer should prevent panning the map view
[gestureRecognizer requireGestureRecognizerToFail:drawerPanGestureRecognizer];
break;
}
}

关于ios - 使 GoogleMap 在使用 MMDrawerController 时保持其位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20208773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com