UIPageViewContoller を使用して、本のようなページめくりエクスペリエンスを作成しています。私の本のページは、iPhone 画面の全幅よりも 18 ピクセル狭く、画面の左側に固定されています。UIPageViewController のビューのフレームは、これらのページのフレーム サイズ (幅:302、高さ:460) に設定されます。これは、ブックに複数のページがあり、iBooks アプリでのエクスペリエンスと同じように、現在表示されているページの端からページめくりが始まるように見える効果を与えるために行います。
私が抱えている問題は、誰かが画面の右端から 302 px ポイントを超えてパンしてページをめくろうとした場合、パン ジェスチャが UIPageViewController によってキャプチャされず、ページがめくられないことです。多くのユーザーがこの方法でページをめくろうとしているのを見てきたので、UI デザインを変更せずにこのエクスペリエンスを修正したいと考えています。
私の考えでは、UIPageViewController の外側の領域から UIPanGesture を取得して、UIPageViewController に渡すことができます。ビュー全体の背景として持っている画像ビューを使用してパン ジェスチャを正常にキャプチャしましたが、ジェスチャを UIPageViewController に渡してページめくりを処理する方法がわかりません。
- (void) viewDidLoad {
...
// Add a swipe gesture recognizer to grab page flip swipes that start from the far right of the screen, past the edge of the book page
self.panGesture = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:nil] autorelease];
[self.panGesture setDelegate:self];
[self.iv_background addGestureRecognizer:self.panGesture];
//enable gesture events on the background image
[self.iv_background setUserInteractionEnabled:YES];
...
}
#pragma mark - UIGestureRecognizer Delegates
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if (self.pageController.view.superview != nil) {
if (gestureRecognizer == self.panGesture) {
// we touched background of the BookViewController, pass the pan to the UIPageViewController
[self.pageController.view touchesBegan:[NSSet setWithObject:touch] withEvent:UIEventTypeTouches];
return YES; // handle the touch
}
}
return YES; // handle the touch
}