0
我正在使用UIPageController來實現基於頁面的導航應用程序。我想僅在頁面邊緣啓用滑動手勢,並阻止來自內部內容視圖的手勢。該頁面具有20個像素的邊距:UIPageController和手勢識別器
contentView.frame = CGRectInset(self.view.frame, 20, 20);
我正在使用UIPageController來實現基於頁面的導航應用程序。我想僅在頁面邊緣啓用滑動手勢,並阻止來自內部內容視圖的手勢。該頁面具有20個像素的邊距:UIPageController和手勢識別器
contentView.frame = CGRectInset(self.view.frame, 20, 20);
一旦識別出你應該能夠檢索locationInView,然後如果這是一個可接受的值進行手勢,否則不是。
首先添加類接口。
@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;
}