修改UIPageViewController行为

iOS5新增加的功能 UIPageViewController 非 常好用,封装了翻页功能操作,只需要给相应对象传入source就可以达到翻页的效果,但是有个问题值得注意,如果你需要在UIPageView添加控 件,默认情况下UIPageViewController是不会处理此控件事件的,解决办法是重写手势处理方法,当用户点击屏幕时,可根据程序里设计的位 置来决定是否需要进行翻页操作。下面的代码是在UIPageViewControllerDelegate实现类下重写 gestureRecognizer方法。

//Insert the following codes into method viewDidLoad of the implement of UIPageViewControllerDelegate
for (UIGestureRecognizer *gR in self.view.gestureRecognizers ) {

    gR.delegate = self;

}

//Override method gestureRecognizer, return false is disabled events.

- ( BOOL )gestureRecognizer : (UIGestureRecognizer * )gestureRecognizer shouldReceiveTouch : (UITouch * )touch {

//Touch gestures below top bar should not make the page turn.

//EDITED Check for only Tap here instead.

    if ( [gestureRecognizer isKindOfClass : [UITapGestureRecognizer class ] ] ) {

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

        if (touchPoint.y > 40 ) { //Which position you want disable the gesture events.

            return NO;

        }

    }

    return YES;

}




http://stephensh.com/archives/680

你可能感兴趣的:(修改UIPageViewController行为)