LeftBarbuttonItem左滑返回&UINavigationBar透明
一. 自定义了leftBarbuttonItem左滑返回手势失效了怎么办?
1. CustomViewController: UIViewController, UIGestureRecognizerDelegate
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "back", style: .Plain, target: self, action: #selector(onBack)) self.navigationController?.interactivePopGestureRecognizer?.delegate = self
Use cocoapods: pod 'FDFullscreenPopGesture'
导入: import FDFullscreenPopGesture 就可以左滑返回
禁止返回:
To disable this pop gesture of a navigation controller:
navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
To disable this pop gesture of a view controller:
viewController.fd_interactivePopDisabled = YES;
如果UINavigationController's -setNavigationBarHidden:animated:
method, instead, use view controller's specific API to hide its bar:
- (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = NO; }
二. 怎么把我的navigationbar弄成透明的而不是带模糊的效果?
1. 可以隐藏navigationbar
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController?.setNavigationBarHidden(true, animated: true) } override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) self.navigationController?.setNavigationBarHidden(false, animated: true) }
2. 设置navigationBar图片
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default) self.navigationController?.navigationBar.shadowImage = UIImage() } override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) self.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: .Default) self.navigationController?.navigationBar.shadowImage = nil }