Last active
July 3, 2021 01:44
-
-
Save fhefh2015/71681d4b9ded4ffa0b90af4d88f6d68f to your computer and use it in GitHub Desktop.
iOS:自定义navigation按钮,侧滑功能失效修复
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// VideoPlayerController.swift | |
// AInOne | |
// | |
// Created by Apple on 2021/7/3. | |
// | |
import UIKit | |
class VideoPlayerController: UIViewController { | |
// 修复侧滑丢失 | |
private var navigationDelegate: UIGestureRecognizerDelegate? | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
navigationDelegate = navigationController?.interactivePopGestureRecognizer?.delegate | |
navigationController?.interactivePopGestureRecognizer?.delegate = self as? UIGestureRecognizerDelegate | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
super.viewWillDisappear(animated) | |
navigationController?.interactivePopGestureRecognizer?.delegate = navigationDelegate | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupUI() | |
// Do any additional setup after loading the view. | |
} | |
} | |
extension VideoPlayerController { | |
func setupUI() { | |
let leftItem = UIBarButtonItem(image: UIImage(systemName: "arrow.left"), style: .plain, target: self, action: #selector(back)) | |
leftItem.tintColor = UIColor.white | |
self.navigationItem.leftBarButtonItem = leftItem | |
} | |
@objc func back() { | |
self.navigationController?.popViewController(animated: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment