我喜欢它的swipe包,它继承于在UINavigationController
中嵌入你的视图。不幸的是,我似乎找不到一种方法来隐藏NavigationBar
,但仍然可以让触摸屏向后刷回gesture
。我可以编写自定义手势,但我不喜欢这样做,而是依赖于UINavigationController
back swipe gesture
。
如果我在情节提要中取消选中它,则向后滑动不起作用
或者,如果我以编程方式隐藏它,同样的情况。
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES animated:NO]; // and animated:YES
}
有没有办法隐藏顶部的NavigationBar
,而仍然有刷卡?
发布于 2014-07-17 23:05:27
一种有效的方法是将UINavigationController
的interactivePopGestureRecognizer
委托设置为nil
:
[self.navigationController.interactivePopGestureRecognizer setDelegate:nil];
但在某些情况下,它可能会产生奇怪的效果。
发布于 2015-03-08 04:00:58
在我的例子中,为了防止奇怪的效果
根视图控制器
override func viewDidLoad() {
super.viewDidLoad()
// Enable swipe back when no navigation bar
navigationController?.interactivePopGestureRecognizer?.delegate = self
}
// UIGestureRecognizerDelegate
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if let navVc = navigationController {
return navVc.viewControllers.count > 1
}
return false
}
发布于 2015-07-13 22:43:16
您可以按如下方式创建UINavigationController的子类:
@interface CustomNavigationController : UINavigationController<UIGestureRecognizerDelegate>
@end
实施:
@implementation CustomNavigationController
- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated {
[super setNavigationBarHidden:hidden animated:animated];
self.interactivePopGestureRecognizer.delegate = self;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if (self.viewControllers.count > 1) {
return YES;
}
return NO;
}
@end
https://stackoverflow.com/questions/24710258
复制相似问题