设备上的火灾隐患从纵向旋转到横向

时间:2018-08-30 19:18:22

标签: swift uiviewcontroller rotation segue

当用户将ViewA中的设备从纵向旋转到横向时,我正在显示ViewB。当ViewB旋转回人像时,我正在展示(撤消回到ViewA)。 ViewA提供详细信息,而与ViewB保持联系则提供图表。这是我的代码:

  

ViewA

override func viewWillAppear(_ animated: Bool)
    {
        UIDevice.current.beginGeneratingDeviceOrientationNotifications()
        NotificationCenter.default.addObserver(self, selector: #selector(ViewA.segueToLandscapeGraph), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
    }

    @objc func segueToLandscapeGraph()
    {
        let deviceOrientation = UIDevice.current.orientation
            print("fired! From ViewA")
        if UIDeviceOrientationIsLandscape(deviceOrientation){
            self.performSegue(withIdentifier: "graphLandscapeSegue", sender: self)
        }
    }
  

ViewB

override func viewWillAppear(_ animated: Bool)
    {
        UIDevice.current.beginGeneratingDeviceOrientationNotifications()

        NotificationCenter.default.addObserver(self, selector: #selector(ViewB.cancelOutOfLandscapeToPortrait), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
    }

    @objc func cancelOutOfLandscapeToPortrait()
    {
        let deviceOrientation = UIDevice.current.orientation
        print("fired! From ViewB")
        if UIDeviceOrientationIsPortrait(deviceOrientation){
            dismiss(animated: true, completion: nil)
        }
    }
    @IBAction func cancelOutOfSegue(_ sender: Any)
    {
        //This button is a failsafe for when app is stuck on this view
        dismiss(animated: true, completion: nil)
    }

这对于前两轮来说效果很好。不管我以哪种方式旋转,它都会卡在ViewB上。为此,我有一个故障保护按钮,可以从ViewB退回到ViewA。

在调试器中,我看到很多东西:如果我们在真正的预提交处理程序中,由于CA限制,我们实际上无法添加任何新的隔离区

  

试图在> MyApp.ViewA:0x7fa893851000上呈现其视图不在窗口层次结构中的ViewB.GraphLabelDetailinLandscape:0x7fa893450360!

0 个答案:

没有答案