使用UIScreenEdgePanGestureRecognizer而不移动MKMapView [英] Use UIScreenEdgePanGestureRecognizer without moving MKMapView

查看:131
本文介绍了使用UIScreenEdgePanGestureRecognizer而不移动MKMapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含MKMapView的UIViewController(事实上,它包含一个包含MKMapView的全屏容器,但不应该有任何影响)

I have a UIViewController containing a MKMapView (in fact, it contains a full screen container containing the MKMapView, but it shouldn't have any impact)

我实现了这样的UIScreenEdgePanGestureRecognizer(显示抽屉):

I implemented a UIScreenEdgePanGestureRecognizer (to show a drawer) like this:

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

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

and to make it works I had to add the following method (returning YES):

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

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

But then the map is moving at the same time as the drawer is appearing! I've tried all kind of tricks to prevent it but was not able to... (I tried shouldBeRequiredToFailByGestureRecognizeror requireGestureRecognizerToFail for example)

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

Any idea how I could prevent the MapView from moving when the gesture is a ScreenEdgePan from LeftEdge?

推荐答案

我在我的应用程序中所做的是以下内容:

What I did in my app was the following:

UIScreenEdgePanGestureRecognizer *popRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePopRecognizer:)];
popRecognizer.edges = UIRectEdgeLeft;
popRecognizer.delegate = self;

然后将代表设置为YES,如你所说

Then set the delegate to YES as you said

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

启用/禁用这样的mapview滚动

And enable/disable scrolling of the mapview like this

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

    }
}

希望有所帮助。

这篇关于使用UIScreenEdgePanGestureRecognizer而不移动MKMapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆