使用自定义后退按钮滑动手势会冻结根视图控制器 [英] Slide gesture with custom back button freezes the root view controller
问题描述
我的应用程序遍布自定义后退按钮,看起来导航控制器不喜欢它。
I have custom back buttons all over my app and it looks like navigation controller does not like it.
所以,我希望iOS7的滑动到后退手势与我的自定义后退按钮一起使用。搜索和尝试不同的方式,但似乎没有一个很有希望。我最接近的是 http://keighl.com /后/ ios7互动-POP-手势自定义后退按钮/ 。
但是,现在,当我继续推送并弹出导航堆栈时,堆栈中的rootViewController在任何时候停止响应任何触摸。
So, I want the iOS7 swipe-to-go-back gesture to work along with my custom back buttons. Searched and tried different ways but none seems to be promising. The closest I could get is with http://keighl.com/post/ios7-interactive-pop-gesture-custom-back-button/. However, Now when I keep pushing and popping the navigation stack, after sometime the rootViewController in the stack stops responding to any touch.
有任何建议吗?
推荐答案
像keighl建议的那样,对UINavigationController进行子类化是正确的方法。但他错过了对根视图控制器的检查,以避免在根视图上执行手势时冻结。
这是带有附加支票的修改版本:
Subclassing UINavigationController, like keighl is suggesting, is the right approach imo. But he's missing a check for the root view controller to avoid freezing when the gesture is executed on the root view. Here's a modified version with the additional check:
CBNavigationController.h:
CBNavigationController.h:
#import <UIKit/UIKit.h>
@interface CBNavigationController : UINavigationController <UIGestureRecognizerDelegate, UINavigationControllerDelegate>
@end
CBNavigationController.m:
CBNavigationController.m:
#import "CBNavigationController.h"
@interface CBNavigationController ()
@end
@implementation CBNavigationController
- (void)viewDidLoad
{
NSLog(@"%s",__FUNCTION__);
__weak CBNavigationController *weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.interactivePopGestureRecognizer.delegate = weakSelf;
self.delegate = weakSelf;
}
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(@"%s",__FUNCTION__);
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
self.interactivePopGestureRecognizer.enabled = NO;
[super pushViewController:viewController animated:animated];
}
#pragma mark UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animate
{
NSLog(@"%s",__FUNCTION__);
// Enable the gesture again once the new controller is shown AND is not the root view controller
if (viewController == self.viewControllers.firstObject)
{
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
self.interactivePopGestureRecognizer.enabled = NO;
}
else
{
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
self.interactivePopGestureRecognizer.enabled = YES;
}
}
@end
< a href =/ questions / tagged / objective-cclass =post-tagtitle =show questions tagged'objective-c' =tag> objective-c
这篇关于使用自定义后退按钮滑动手势会冻结根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!