Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift中将viewcontroller拖动到tabbarcontroller时,黑屏可见?_Ios_Swift_Uitabbarcontroller_Tabbarcontroller_Dismissviewcontroller - Fatal编程技术网

Ios 在swift中将viewcontroller拖动到tabbarcontroller时,黑屏可见?

Ios 在swift中将viewcontroller拖动到tabbarcontroller时,黑屏可见?,ios,swift,uitabbarcontroller,tabbarcontroller,dismissviewcontroller,Ios,Swift,Uitabbarcontroller,Tabbarcontroller,Dismissviewcontroller,当我从TabbarController向外部Viewcontroller正确显示并正确关闭时。但当我拖动以关闭Viewcontroller时,它会使用UIPangestureRecognitor显示黑屏 从TabbarController到ViewController显示代码 let newVC = self.storyboard?.instantiateViewController(withIdentifier: "ExampleViewController") as! ExampleVi

当我从TabbarController向外部Viewcontroller正确显示并正确关闭时。但当我拖动以关闭Viewcontroller时,它会使用UIPangestureRecognitor显示黑屏

从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
    }
}
注意:-我的项目层次结构类似于以下导航控制器-->SomeViewController-->TabbarViewController-->ExampleViewController


提前感谢

将导航控制器插入

TabbarViewController-->示例ViewController

因此,它应该是:

TabbarViewController-->导航控制器-->示例ViewController

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

尝试了您的代码,只需在选项卡屏幕和视图控制器之间提供导航控制器

let newVC = self.storyboard?.instantiateViewController(withIdentifier: "ExampleViewController") as! ExampleViewController
newVC.modalPresentationStyle = .overCurrentContext
self.present(newVC, animated: true, completion: nil)
在下一个屏幕中,使用了和上面提到的相同的功能,没有黑屏

或者,您可以按照此处的建议,在
AppDelegate
中使用以下行:


window?.backgroundColor=UIColor.white

你能分享你的用户界面截图吗?你是说我的用户界面中的ExampleViewController?这不是拖动视图控制器视图的方法。您需要一个自定义的交互式过渡动画。请删除以下行:
newVC.modalPresentationStyle=.overCurrentContext
,然后重试拖动。@Niraj,我也删除了这一行,但无法正常工作。我的代码中还有其他需要更改的内容吗?我不想使用Segue方法。而且,如果没有NavigationController,例如ViewController,它对我来说很好。如果不需要,您也可以将present与navigation controller一起使用,并隐藏navigationbar。我还尝试了此方法,让newVC:AddActivityVC=self.storyboard?.InstanceEviewController(标识符为:“ExampleViewController”)为!ExampleViewController让navigationController=UINavigationController(rootViewController:newVC)self.navigationController?.pushViewController(newVC,动画:true)但不工作,我使用present代替push保持不变如下:让ExampleViewController=self.storyboard?.InstanceViewController(带标识符:“ExampleViewController”)作为!ExampleViewController让navigationController=UINavigationController(rootViewController:ExampleViewController)navigationController.modalPresentationStyle=UIModalPresentationStyle.overCurrentContext self.present(navigationController,动画:true,完成:nil)我尝试了u所说的,但仍然保持黑屏。我想在UI或代码中更改什么?当我尝试使用Viewcontroller来示例Viewcontroller时,它工作良好实际上,当关闭Viewcontroller到Viewcontroller时,在没有黑屏的情况下工作良好。但当谈到Viewcontroller到TabbarController时,它不工作。它显示黑色s屏幕。拖动到dismissI时,我更新了我的UI。请检查您的UI是否完美。您从何处显示您的
ExampleViewController
tabbar或tabbar的第一视图控制器?