更改ViewController后,场景转换不再起作用

时间:2016-10-28 15:28:54

标签: ios swift

以下是我在不同ViewControllers之间导航的方式:

let newViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "viewController3")
UIApplication.topViewController()?.present(newViewController, animated: true, completion: nil)

具有以下扩展名:

extension UIApplication {
class func topViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
    if let nav = base as? UINavigationController {
        return topViewController(base: nav.visibleViewController)
    }
    if let tab = base as? UITabBarController {
        if let selected = tab.selectedViewController {
            return topViewController(base: selected)
        }
    }
    if let presented = base?.presentedViewController {
        return topViewController(base: presented)
    }
    return base
}

}

以下是我在SKScene(几个)中调用场景转换的方式:

let transition = SKTransition.fade(withDuration: 2)
let nextScene = NewScene(size: scene!.size)
nextScene.scaleMode = .aspectFill
scene?.view?.presentScene(nextScene, transition: transition)

切换ViewControllers之前一切正常。一旦切换成功,我就无法在我的SKScene中调用转换,应用程序被冻结而没有来自Xcode的任何错误(iPad通过实时调试连接到Mac)

你知道会发生什么吗?

我将Swift 3和SpriteKit与ViewControllers一起使用,以便能够在直接的ViewController场景(UIView)中使用Vuforia静态库。

1 个答案:

答案 0 :(得分:0)

我终于找到了解决方案,在使用新的ViewController进行更改之前需要关闭它:

fn naive_largest_path(root: Rc<RefCell<Node>>) {
    let mut cur_node = root.clone();
    let cur_node_borrowed = cur_node.borrow();

    // while cur_node_borrowed.has_children() {
        let lc = cur_node_borrowed.left_child.as_ref().unwrap();

        let left_child = cur_node_borrowed.left_child.as_ref().unwrap();
        let right_child = cur_node_borrowed.right_child.as_ref().unwrap();

        let left_val = left_child.borrow().value;
        let right_val = right_child.borrow().value;

        if left_val > right_val {
            cur_node = left_child.clone();
        } else {
            cur_node = right_child.clone();
        }
    // }
}

struct Node {
    value: i32,
    row_num: i32,
    position_in_row: i32,
    left_child: Option<Rc<RefCell<Node>>>,
    right_child: Option<Rc<RefCell<Node>>>,
}

impl Node {
    fn new(val: i32, row: i32, pos_in_row: i32) -> Rc<RefCell<Node>> {
        Rc::new(RefCell::new(Node {
            value: val,
            row_num: row,
            position_in_row: pos_in_row,
            left_child: None,
            right_child: None,
        }))
    }

    fn has_children(&self) -> bool {
        self.left_child.is_some() || self.right_child.is_some()
    }
}

如果没有完成解雇通话,则无法在新的ViewController中执行新的转换场景。