带有UIScreenEdgeGestureRecognizer的SWRevealViewController panGestureRecognizer

时间:2015-08-05 13:12:04

标签: ios objective-c swrevealviewcontroller

我一直在寻找这个问题的解决方案,但没找到任何一个。所以我在我的项目中使用SWRevealViewController作为侧边栏菜单,但我希望当用户从视图的左边缘触摸时会打开侧边菜单。我想要这个,因为我有另一个swipeGestureRecognizer用于向左和向右滑动。为了添加左右滑动,我使用此代码:

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipedToRight:)];
        swipeRight.direction = UISwipeGestureRecognizerDirectionRight;

   UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @selector(swipedToLeft:)];
       swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;

所以我的问题是,只有当触摸从左边缘开始时,如何才能打开侧边菜单?

UPD 1

我使用此代码通过在屏幕的任何部分平移来打开侧边菜单

[self.view addGestureRecognizer: self.revealViewController.panGestureRecognizer];

我有识别器向右滑动。问题是一旦打开菜单并执行滑动操作。我想仅在触摸来自左边缘时才允许打开菜单

UPD 2已解决

我通过设置可拖动的边框宽度来解决它:

self.revealViewController.draggableBorderWidth = self.view.frame.size.width / 2;

现在从边缘到中心的手势打开菜单,从中心到右边框执行滑动操作

3 个答案:

答案 0 :(得分:1)

您可以添加之前提到的UIPanGestureRecognizer,也可以在视图顶部添加一个子视图,并为其添加一个手势:

UIView *topView = ...
[self.view addSubview: topView];

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]
                                   initWithTarget:self action:@selector(didPan:)];

[topView addGestureRecognizer:pan];

答案 1 :(得分:1)

我要做的是修改if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; // Your code here } 类中已经存在的pop手势。

要添加到viewWillAppear的示例代码:

  Var1(REG1, 0U, 16U);
  Var2(REG2, 0U, 8U);

   UINT32 FirstReg = Getaddress1(Var1); //the dimension is 16 bit

   FirstReg = ((FirstReg >> 1) & 0x5555) | ((FirstReg << 1) & 0xaaaa);
   FirstReg = ((FirstReg >> 2) & 0x3333) | ((FirstReg << 2) & 0xcccc);
   FirstReg = ((FirstReg >> 4) & 0x0f0f) | ((FirstReg << 4) & 0xf0f0);
   FirstReg = ((FirstReg >> 8) & 0x00ff) | ((FirstReg << 8) & 0xff00);
   FirstReg = (FirstReg << 8);

   UINT32 SecondReg = Getaddress2(Var2);//the dimension is 8 bit
   SecondReg = ((SecondReg >> 1) & 0x5555) | ((SecondReg << 1) & 0xaaaa);
   SecondReg = ((SecondReg >> 2) & 0x3333) | ((SecondReg << 2) & 0xcccc);
   SecondReg = ((SecondReg >> 4) & 0x0f0f) | ((SecondReg << 4) & 0xf0f0);
   SecondReg = ((SecondReg >> 8) & 0x00ff) | ((SecondReg << 8) & 0xff00);
   SecondReg = (SecondReg >> 8);

   return (FirstReg | SecondReg);

答案 2 :(得分:1)

我要做的是修改UINavigationController类中内置的已经存在的弹出手势。