Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Last active July 3, 2021 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhefh2015/71681d4b9ded4ffa0b90af4d88f6d68f to your computer and use it in GitHub Desktop.
Save fhefh2015/71681d4b9ded4ffa0b90af4d88f6d68f to your computer and use it in GitHub Desktop.
iOS:自定义navigation按钮,侧滑功能失效修复
//
// 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