gpt4 book ai didi

ios7 - 带有自定义后退按钮的滑动手势会卡住 Root View Controller

转载 作者:行者123 更新时间:2023-12-05 00:26:31 25 4
gpt4 key购买 nike

我的应用程序中到处都是自定义后退按钮,看起来导航 Controller 不喜欢它。

所以,我希望 iOS7 滑动返回手势与我的自定义后退按钮一起使用。搜索并尝试了不同的方法,但似乎没有一个有希望。我能得到的最接近的是 http://keighl.com/post/ios7-interactive-pop-gesture-custom-back-button/ .
但是,现在当我继续推送和弹出导航堆栈时,一段时间后堆栈中的 rootViewController 停止响应任何触摸。

有什么建议?

最佳答案

就像 keighl 建议的那样,继承 UINavigationController 是正确的方法。但是他没有检查根 View Controller 以避免在根 View 上执行手势时卡住。
这是带有附加检查的修改版本:

CBNavigationController.h:

#import <UIKit/UIKit.h>

@interface CBNavigationController : UINavigationController <UIGestureRecognizerDelegate, UINavigationControllerDelegate>
@end

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

关于ios7 - 带有自定义后退按钮的滑动手势会卡住 Root View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22051350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com