UIPageController和手势识别器

时间:2012-05-15 06:30:24

标签: ios uigesturerecognizer

我正在使用UIPageController来实现基于页面的导航应用程序。我想仅在页面的边缘启用滑动手势,并从内部内容视图中阻止该滑动手势。该页面的边距为20像素:

contentView.frame = CGRectInset(self.view.frame, 20, 20);

2 个答案:

答案 0 :(得分:1)

识别出手势后,您应该能够检索locationInView,然后如果这是可接受的值,则继续,否则不会。

答案 1 :(得分:0)

首先添加类接口。

@interface MyPageViewController :UIViewController<UIPageViewControllerDelegate, UIGestureRecognizerDelegate>

然后在viewDidLoad中添加

for (UIGestureRecognizer *recognizer in self.pageViewController.gestureRecognizers) {

        recognizer.delegate = self;

}

然后实现shouldReceiveTouch方法

#pragma mark - UIGestureRecognizer delegate methods
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{


    CGPoint touchPoint = [touch locationInView:self.pageViewController.view];

    CGRect innerRect =  CGRectInset(self.pageViewController.view.frame, 40, 40);

   if (CGRectContainsPoint(innerRect, touchPoint)) {
        return NO;
   }

   return YES;
}