当我从 TabbarController 呈现到外部 Viewcontroller 正确呈现并且正确关闭时。但是当我拖动以关闭 ViewController 时,它使用 UIPanGestureRecognizer 显示黑屏。
从 TabbarController 到 ViewController 呈现代码
let newVC = self.storyboard?.instantiateViewController(withIdentifier: "ExampleViewController") as! ExampleViewController
self.definesPresentationContext = true
newVC.modalPresentationStyle = .overCurrentContext
self.present(newVC, animated: true, completion: nil)
关闭 ExampleViewController 到 TabbarController 代码
override func viewDidLoad()
{
super.viewDidLoad()
let gestureRecognizer = UIPanGestureRecognizer(target: self,
action: #selector(panGestureRecognizerHandler(_:)))
view.addGestureRecognizer(gestureRecognizer)
}
@IBAction func panGestureRecognizerHandler(_ sender: UIPanGestureRecognizer) {
let touchPoint = sender.location(in: view?.window)
var initialTouchPoint = CGPoint.zero
switch sender.state {
case .began:
initialTouchPoint = touchPoint
case .changed:
if touchPoint.y > initialTouchPoint.y {
view.frame.origin.y = touchPoint.y - initialTouchPoint.y
}
case .ended, .cancelled:
if touchPoint.y - initialTouchPoint.y > 200 {
self.navigationController?.popViewController(animated: false)
} else {
UIView.animate(withDuration: 0.2, animations: {
self.view.frame = CGRect(x: 0,
y: 0,
width: self.view.frame.size.width,
height: self.view.frame.size.height)
})
}
case .failed, .possible:
break
@unknown default:
break
}
}
注意:- 我的项目层次结构像这样 NavigationController --> SomeViewControllers -->TabbarViewController-->ExampleViewController
提前致谢