我怀疑有两个问题是相互关联的。
我有一个支持横向方向的通用应用。我的应用程序启动(使用界面构建器启动屏幕),然后显示SKScene。我有三大问题。
我想您可能有兴趣看到以下内容:
摘自viewController:
import UIKit
import SpriteKit
import AVFoundation
import GameKit
import CoreData
import iAd
extension SKNode {
class func unarchiveFromFile(file : String) -> SKNode? {
if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") {
var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)!
var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene
archiver.finishDecoding()
return scene
} else {
return nil
}
}
}
class GameViewController: UIViewController, SceneTransitionDelegate, GKGameCenterControllerDelegate, ADBannerViewDelegate {
var audioPlayers:[AVAudioPlayer] = []
var sounds:[NSURL] = []
var nextSongDelay:NSTimer = NSTimer()
var currentSong:AVAudioPlayer = AVAudioPlayer()
var disp:CGFloat = 0
var starget:String = "HI"
var soundEffects:[AVAudioPlayer] = []
var rwidth:CGFloat = 0
var rheight:CGFloat = 0
var skView:SKView { return view as! SKView }
//var skView:SKView { return view as! SKView }
var iadp:Bool = false
var ar:Bool = true
var uord:Bool = false
override func viewDidLoad() {
super.viewDidLoad()
theEssence = self
launchAudio()
//mediumRectAdView!.delegate = self;
let defaults = NSUserDefaults.standardUserDefaults()
if (isAppAlreadyLaunchedOnce() == false)
{
defaults.setBool(false, forKey: "player")
}
if (defaults.boolForKey("Toothachepunlockiad") == true)
{
s_manualoverride.self = true
iAdBanner.hidden = true
}
// Configure the view.
let skView = self.view as! SKView
//skView.showsFPS = true
//skView.showsNodeCount = true
skView.showsPhysics = false
delli = self
authenticateLocalPlayer()
iAdBanner.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.width, 50)
iAdBanner.delegate = self
bannerVisible = false
iAdBanner.hidden = false
ar = true
self.shouldAutorotate()
transitionToScene(Menu.self)
}
//SceneTransitionDelegate method
func transitionToScene(sceneClass:Scene.Type) {
playing = false
var sizeRect = UIScreen.mainScreen().applicationFrame
var width = sizeRect.size.width
var height = sizeRect.size.height
let skView = self.view as! SKView
let scene = sceneClass(size: skView.bounds.size)
scene.size = CGSizeMake(width, height)
rwidth = width
rheight = height
swidth = width
sheight = height
skView.ignoresSiblingOrder = true
scene.scaleMode = .AspectFill
scene.sceneDelegate = self
skView.presentScene(scene)
}
func transitionToScene(sceneClass: Scene.Type, transitionAnimation: SKTransition)
{
playing = false
var sizeRect = UIScreen.mainScreen().applicationFrame
var width = sizeRect.size.width
var height = sizeRect.size.height
let skView = self.view as! SKView
let scene = sceneClass(size: skView.bounds.size)
scene.size = CGSizeMake(width, height)
rwidth = width
rheight = height
swidth = width
sheight = height
skView.ignoresSiblingOrder = true
scene.scaleMode = .AspectFill
scene.sceneDelegate = self
skView.presentScene(scene, transition: transitionAnimation)
}
override func shouldAutorotate() -> Bool {
return ar
}
override func supportedInterfaceOrientations() -> Int {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
} else {
return Int(UIInterfaceOrientationMask.All.rawValue)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
if (playing == true)
{
println("MEMORY WARNING WE ARE DIEING")
//fatalError("MEMORY WARNING WE AARE ALL GOING TO DIE")
}
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
if(bannerVisible == false) {
// Add banner Ad to the view
if(iAdBanner.superview == nil) {
self.view.addSubview(iAdBanner)
}
// Move banner into visible screen frame:
UIView.beginAnimations("iAdBannerShow", context: nil)
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height)
UIView.commitAnimations()
bannerVisible = true
}
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
if(bannerVisible == true) {
// Move banner below screen frame:
UIView.beginAnimations("iAdBannerHide", context: nil)
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height)
UIView.commitAnimations()
bannerVisible = false
}
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
// Configure the view.
let skView = self.view as! SKView
skView.paused = true
return true
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
let skView = self.view as! SKView
skView.paused = false
}
}
我最近做过的一些事情可能会触发这个: 添加了结构崩溃报告 添加了自动旋转