0

当我从 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

在此处输入图像描述

提前致谢

4

2 回答 2

0

在中间插入导航控制器

TabbarViewController-->ExampleViewController

所以应该是:

TabbarViewController--> NavigationController-->ExampleViewController

只需选择 ExampleViewController 选择在情节提要中嵌入导航控制器。并使用 Segue 推送方法。

于 2020-03-05T13:31:49.373 回答
0

尝试了您的代码,只需提供NavigationController选项卡屏幕和您的视图控制器之间的内容。

let newVC = self.storyboard?.instantiateViewController(withIdentifier: "ExampleViewController") as! ExampleViewController
newVC.modalPresentationStyle = .overCurrentContext
self.present(newVC, animated: true, completion: nil)

并且在下一个屏幕中使用了与您上面提到的相同的功能,没有黑屏。

AppDelegate或者您可以按照此处的建议使用以下行: https ://stackoverflow.com/a/45994837/12830762

window?.backgroundColor = UIColor.white

于 2020-03-05T14:01:32.330 回答