应用程序没有填满设备屏幕,也没有启动屏幕自动旋转

时间:2015-09-24 00:55:27

标签: ios swift sprite-kit xib

我怀疑有两个问题是相互关联的。

我有一个支持横向方向的通用应用。我的应用程序启动(使用界面构建器启动屏幕),然后显示SKScene。我有三大问题。

  1. 在应用程序加载时,在iPad上,仅在iPad(iOS 8或9)上,所有图像都丢失,只留下文本。此外,发射屏幕的显示区域比实际设备显示小约一厘米。这不是iPhone上的问题
  2. 在ipads上,并且仅在iPad(iOS 8或9)上由于某种原因整个应用程序发生在它周围的边框。我的应用占用的屏幕区域小于实际设备。这对iPhone来说不是问题。
  3. 我的应用设置为自动旋转" shouldAutoRotate()"功能。但是我无法让发射屏幕以正确的方向发射。
  4. 我想您可能有兴趣看到以下内容:

    摘自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
        }
    }
    

    我最近做过的一些事情可能会触发这个: 添加了结构崩溃报告 添加了自动旋转

    Picture of it

1 个答案:

答案 0 :(得分:0)

我在iPhone 6 Plus上遇到了类似的问题。原因是缺少加载该设备显示尺寸的图像。检查您是否加载了所有必需尺寸和方向的图像。正如您在图片中看到的那样,Xcode会告诉您特定图像的大小。希望这能解决你的问题。

enter image description here