从纵向模式返回到横向模式时出现快速错误

时间:2016-03-15 08:21:58

标签: swift homekit

我的应用程序刚刚设置了横向模式。我只使用The Table View在家里添加配件。

enter image description here

我的问题是,当我添加新配件时,我的应用程序进入纵向模式以打开设置窗口代码

enter image description here

用于配对附件,成功完成作业后,表视图返回第一个黑色窗口但保持纵向模式。我试图通过

在AppDelegate中稳定这个
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {


    if (shouldSupportAllOrientation == true){
        return UIInterfaceOrientationMask.Portrait
    }

    if (shouldSupportAllOrientation == false){
        return UIInterfaceOrientationMask.Landscape
    }

    return UIInterfaceOrientationMask.Landscape

    }}

和我的TableViewController

import UIKit
import HomeKit

class TableViewController: UITableViewController, HMAccessoryBrowserDelegate {

let homeManager = HMHomeManager()
let browser = HMAccessoryBrowser()
let appdelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var accessories = [HMAccessory]()


  override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

  let accessory = accessories[indexPath.row] as HMAccessory

    if let home = homeManager.primaryHome {

        for room in home.rooms {

            if room.name == “Kitchen” {

                self.appdelegate.shouldSupportAllOrientation = true

                homeManager.primaryHome?.addAccessory(accessory, completionHandler: { (error) -> Void in

                 if error != nil {

                        print("ERROR 1 \(error?.localizedDescription)")
                      }
                    else {

                        self.homeManager.primaryHome?.assignAccessory(accessory, toRoom: room, completionHandler: { (error) -> Void in

                            if error != nil {

                                print("ERROR 2 \(error?.localizedDescription)")
                            } else {
                                print("Accessory Add successfully")
                                self.appdelegate.shouldSupportAllOrientation = false
                                self.performSegueWithIdentifier(“goToBlackView”, sender: self)

                            }})}})}}}

}}

但是当黑色视图回来时,我的设备似乎被锁定在人像模式中,但是一旦我做了迷你摇动手机几秒钟后,黑色视图又回到了陆地模式。我该如何克服这个问题呢?

编辑:

我已在此模式下设置故事板

enter image description here

但我有这个错误

  

***由于未捕获的异常'UIApplicationInvalidInterfaceOrientation'终止应用程序,原因:'支持的方向与应用程序没有共同的方向,[HMSetupViewController shouldAutorotate]返回YES'

0 个答案:

没有答案