ios – 使用UIScreenEdgePanGestureRecognizer而不移动MKMapView

前端之家收集整理的这篇文章主要介绍了ios – 使用UIScreenEdgePanGestureRecognizer而不移动MKMapView前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个包含MKMapView的UIViewController(事实上,它包含一个包含MKMapView的全屏容器,但它不应该有任何影响)

我实现了一个UIScreenEdgePanGestureRecognizer(显示抽屉),如下所示:

self.swipeRight = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleEdgeGesture:)];
[self.swipeRight setEdges:UIRectEdgeLeft];
[self.swipeRight setDelegate:self];
[self.view addGestureRecognizer:self.swipeRight];

并使其工作我必须添加以下方法(返回YES):

(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

但随后地图在抽屉出现的同时移动!
我已经尝试过各种各样的技巧来阻止它但是却无法……(我试过了例如shouldBerequiredToFailByGestureRecognizeror requireGestureRecognizerToFail)

有什么想法,当手势是来自LeftEdge的ScreenEdgePan时,我怎么能阻止MapView移动?

解决方法

我在我的应用程序中所做的是以下内容
UIScreenEdgePanGestureRecognizer *popRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePopRecognizer:)];
popRecognizer.edges = UIRectEdgeLeft;
popRecognizer.delegate = self;

然后如你所说,将委托设置为YES

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

并启用/禁用这样的mapview滚动

- (void)handlePopRecognizer:(UIScreenEdgePanGestureRecognizer*)recognizer
{
    if(recognizer.state == UIGestureRecognizerStateBegan){
        _mapView.scrollEnabled = NO;
    } else if(recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled){
        _mapView.scrollEnabled = YES;

    }
}

希望能帮助到你.

猜你在找的iOS相关文章