5

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
}
4

1 に答える 1

5

UIPageViewController には、gestureRecognizers プロパティがあります。ドキュメントは、あなたが探しているものを正確に説明しているようです:

ジェスチャレコグナイザー

ユーザー操作を処理するように構成された UIGestureRecognizer オブジェクトの配列。(読み取り専用)

@property(nonatomic, readonly) NSArray *gestureRecognizers

討論

これらのジェスチャ レコグナイザーは、最初にページ ビュー コントローラーの階層内のビューにアタッチされます。ユーザーがジェスチャを使用してナビゲートできる画面の領域を変更するには、ジェスチャを別のビューに配置します。

可用性

iOS 5.0 以降で利用できます。で宣言

UIPageViewController.h

于 2012-06-07T21:35:34.197 に答える