When i am presenting from TabbarController to Outside Viewcontroller presenting correctly and also Dismiss correctly.but when i drag to dismiss the ViewController it show's Black screen using UIPanGestureRecognizer.
From TabbarController to ViewController Present Code
let newVC = self.storyboard?.instantiateViewController(withIdentifier: "ExampleViewController") as! ExampleViewController
self.definesPresentationContext = true
newVC.modalPresentationStyle = .overCurrentContext
self.present(newVC, animated: true, completion: nil)
Dismiss ExampleViewController to TabbarController Code
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
}
}
Note:- My Project hierarchy like this NavigationController --> SomeViewControllers -->TabbarViewController-->ExampleViewController
Thanks in advance
Tried your code, just provide the NavigationController
between tab screen and your view controller.
let newVC = self.storyboard?.instantiateViewController(withIdentifier: "ExampleViewController") as! ExampleViewController
newVC.modalPresentationStyle = .overCurrentContext
self.present(newVC, animated: true, completion: nil)
And in next screen used same function as you mentioned above, no black screen.
Or you can use below line in AppDelegate
as suggested here: https://stackoverflow.com/a/45994837/12830762
window?.backgroundColor = UIColor.white