UIScreenEdgePanGestureRecognizer激活SWRevealViewController平移手势

时间:2014-08-18 07:49:56

标签: ios user-interface uipangesturerecognizer uiswipegesturerecognizer swrevealviewcontroller

我正在使用SWRevealViewController作为侧边栏,我必须使用滑动来查看我的上一个和下一个故事以及边栏的边栏。

我使用UIScreenEdgePanGestureRecognizer而不是PanGestureRecogniser的原因是因为滑动会结束调用平移手势,导致整个页面变得混乱。我希望有一种方法可以在激活边缘平移识别器时调用平移手势,而不是使用它:

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


[[BTHomeViewController sharedInstance].revealViewController.panGestureRecognizer requireGestureRecognizerToFail: left];
[[BTHomeViewController sharedInstance].revealViewController.panGestureRecognizer requireGestureRecognizerToFail: right];

我想使用SWRevealVC的委托。如果还有其他方式,请向我建议。

UIScreenEdgePanGestureRecognizer *panLeft = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleRevealGesture:)];
[panLeft setEdges:UIRectEdgeLeft];
panLeft.minimumNumberOfTouches = 1;
panLeft.maximumNumberOfTouches = 1;
[self.view addGestureRecognizer:panLeft];

代表SWRevealVC的方法

// The following methods provide a means to track the evolution of the gesture recognizer.
// The 'location' parameter is the X origin coordinate of the front view as the user drags it
// The 'progress' parameter is a positive value from 0 to 1 indicating the front view location relative to the
// rearRevealWidth or rightRevealWidth. 1 is fully revealed, dragging ocurring in the overDraw region will result in values above 1.
- (void)revealController:(SWRevealViewController *)revealController panGestureBeganFromLocation:(CGFloat)location progress:(CGFloat)progress;
- (void)revealController:(SWRevealViewController *)revealController panGestureMovedToLocation:(CGFloat)location progress:(CGFloat)progress;
- (void)revealController:(SWRevealViewController *)revealController panGestureEndedToLocation:(CGFloat)location progress:(CGFloat)progress;

1 个答案:

答案 0 :(得分:5)

要用UIScreenEdgePanGestureRecognizer替换UIPanGestureRecognizer,请执行以下操作:

  • 转到SWRevealViewController
  • 查找并替换UIPanGestureRecognizer UIScreenEdgePanGestureRecognizer
  • 最重要的设置边

    _panGestureRecognizer.edges = UIRectEdgeLeft;