18

内にネストされたView ControllerがありますUINavigationController

iOS 7 interactivePopGestureRecognizer を実装して、ユーザーがジェスチャで VC をスタックからポップできるようにしました。

VC 内にスクロールビューがあり、ユーザーがスクロールビューの一番上にいない間は、すべてのクロム (ナビゲーション バーとステータス バー) を非表示にして、コンテンツにフォーカスを置きます。

ただし、ナビゲーション バーが非表示になっていると、interactivePopGestureRecognizer が機能しません。

消えてから有効にしようとしましたが、nil ではないことを確認しましたが、まだ機能しません。

不足しているものはありますか?

4

5 に答える 5

37

UIViewController サブクラスを、gestureRecognizer のデリゲートとして設定します。

self.navigationController.interactivePopGestureRecognizer.delegate = self;

それでおしまい!

于 2013-11-07T10:58:46.427 に答える
7

これを使いました。 self.navigationController.interactivePopGestureRecognizer.delegate = self;

また、UINavigationController クラスで、遷移中に interactivePopGestureRecognizer を無効にします。

- (void)pushViewController:(UIViewController *)viewController
              animated:(BOOL)animated
{
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = NO;
}

    [super pushViewController:viewController animated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        // disable interactivePopGestureRecognizer in the rootViewController of navigationController
        if ([[navigationController.viewControllers firstObject] isEqual:viewController]) {
            navigationController.interactivePopGestureRecognizer.enabled = NO;
        } else {
            // enable interactivePopGestureRecognizer
            navigationController.interactivePopGestureRecognizer.enabled = YES;
        }
    }
}

rootViewController で interactivePopGestureRecognizer を無効にする理由は次のとおりです。rootViewController の端からスワイプしてから何かをタップして次の viewController にプッシュすると、UI は現在タッチを受け付けません。ホーム ボタンを押してアプリをバックグラウンドにし、タップして入力します。前景...

于 2014-02-07T10:54:42.187 に答える
3

これは私にはうまくいかないようです。Keithl のブログ記事をフォローしました。それもうまくいきませんでした。

私は最終的に解決しましたUISwipeGestureRecognizer。言われたとおりにするそうです。

UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(backButtonPressed:)];
[gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.navigationController.view addGestureRecognizer:gestureRecognizer];
于 2013-12-27T23:24:20.690 に答える
0

これらの2行を追加すると-(void)viewDidAppear:(BOOL)animatedうまくいきました。

self.navigationController.navigationBarHidden = NO;
self.navigationController.navigationBar.hidden = YES;

ファイルに電話<UIGestureRecognizerDelegate>することを忘れないでください。.h

于 2015-11-14T18:45:00.397 に答える