0

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

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

2 回答 2

1

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

于 2012-05-15T15:46:26.257 回答
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;
}
于 2012-05-16T03:48:59.787 回答