2014年5月15日木曜日

iOS7 UINavigationController Interactive Pop Gesture 問題解決

iOS7から追加されたInteractivePopGesture(Swipeで前の画面に戻る)機能が、
NavigationBarのleftBarButtonItemを置き換えた場合動かなくなる問題の解決。

参照サイト : http://keighl.com/post/ios7-interactive-pop-gesture-custom-back-button/

上記の参照サイトでほぼ解決だけど、
rootViewでSwipeをすると固まる現象が発生したので少し修正して解決。

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animate
{
    // Enable the gesture again once the new controller is shown
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        if ([self.viewControllers count] > 1) {
            self.interactivePopGestureRecognizer.enabled = YES;
        } else {
            // rootViewの場合
            self.interactivePopGestureRecognizer.enabled = NO;
        }
    }
}

以上。