导航栏

Swift - 自定义导航栏的返回按钮

2018-02-07  本文已影响0人  麦志超

Github https://github.com/MZC0829/MBack

MBack

Custom backBarButtonItem in Swift.

Cocoapods

1. Add the following line to your Podfile:

platform :ios, '9.0'

target 'YourIosApps' do

  use_frameworks!

  pod 'MBack', '~> 1.0.0'

end

2. Then, run the following command:

$ pod install

Carthage

1、run the following command:

$ touch Cartfile

2、Add the following line to your Cartfile:

github "MZC0829/MBack"

3、run the following command:

$ carthage update

Requirements

Usage

- just like

override func viewWillAppear(_ animated: Bool)
{
    super.viewWillAppear(animated)
        
    self.MBackButton(image: "Your custom back image")
}

- or

override func viewWillAppear(_ animated: Bool)
{
    super.viewWillAppear(animated)
        
    self.MBackButton(image: "Your custom back image", popMethod: ENUMPopMethod.Root, title: "Back")
}

PS

自定义返回按钮后,屏幕左边缘滑动返回会失效,解决办法如下:

1、让 ViewController 继承 UIGestureRecognizerDelegate
2、
override func viewDidLoad()
{
    super.viewDidLoad()
    self.navigationController?.interactivePopGestureRecognizer?.delegate = self        
}
3、
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool
{
        if gestureRecognizer == self.navigationController?.interactivePopGestureRecognizer
        {
            return self.navigationController!.viewControllers.count > 1
        }
        return true      
}

上一篇下一篇

猜你喜欢

热点阅读