2015-10-14 47 views
1
 UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 6, options: [], animations: ({ 

     self.background.center.x = self.view.frame.width + 600 
     self.PlayButton.center.x = self.view.frame.width + 600 
     self.infoButton.center.x = self.view.frame.width + 600 
     self.logo.center.x = self.view.frame.width + 600 
     self.infoHidden.center.x = self.view.frame.width + 600 
     self.settingsButton.center.x = self.view.frame.width + 600 
     self.shareButton.center.x = self.view.frame.width + 600 
     //self.adBanner.center.x = self.view.frame.width + 600 
     self.view.frame.width + 800 

    }), completion: nil) 

    let View2 = self.view as! SKView  // View 
    View2.ignoresSiblingOrder = false  // Perfomance 
    let Play = GameScene()     // Game 
    Play.scaleMode = .ResizeFill   // Scale 
    View2.presentScene(Play)    // Present 

爲什麼這個代碼返回例外「無法投型的價值‘的UIView’(0x1f1ed90)爲‘SKView’」?該代碼在早期工作,突然間它開始拋出異常。我的視圖的類被設置爲故事板中的SKView。奇怪的是,當我在遊戲中實現iad時,這個異常纔開始拋出。有什麼我失蹤?當我垂頭喪氣的UIView到SKView,我得到一個異常

回答

1

我認爲this thread會幫你的,特別是這句話

SKView是的UIView的子類。 UIViewController的視圖可以是任何類型的UIView對象,它不一定具體是UIView對象的一個​​UIView 。

注意,此代碼仍然可以在運行時失敗,如果認爲不是一個 SKView(例如,如果它實際上是一個UIView對象),所以你必須要 肯定。

要點是,你的UIView,你下來鑄造可能不是一個SKView,而是一個UIView,所以你得到一個運行時異常。嘗試使用可選的downcast作爲?並處理倒下失敗的情況。

相關問題