2016-04-12 4 views
3

サブビュー(SKView)の正しいサイズを取得/設定しようとしています。サイズの見方SKViewサブビューとSKSceneは正しく

私はストーリーボードを使用してUIViewを作成し、サブビューはSKViewです。私はSKViewの寸法を持つSKSceneをプログラムで作成したいと思います。

私の考えは、scene.size.heightscene.size.widthは、SKViewの高さと幅に等しいと考えています。これをテストするために、私は各コ​​ーナーに4つの青い円を描画し、境界線には赤い線を描いています。私は青いコーナーの4つのドットと境界線をすべて見たいと思っているときに、左下を見ることしかできません。

シーン内の黒丸は無視してください。無関係です。

iPhone 6スクリーンショット(肖像画)
iPhone 6 Screenshot (portrait)

iPhone 6スクリーンショット(ランドスケープ) iPhone 6 Screenshot (landscape)

私はSW(南西)、SE、NE、およびNWラベルを追加

ViewController SKViewリファレンス 私はSKSCene Main.storyboard

制約(func newGameを参照)

import UIKit 
import SpriteKit 


class CenterView: UIViewController, ActionDelegate { 
    @IBOutlet weak private var navBar:UINavigationBar! 
    @IBOutlet weak private var titleBar:UINavigationItem! 
    @IBOutlet weak private var gameView:SKView! 

    var navigation:NavigationDelegate? 
    var action:ActionDelegate? 
    var game:GameDelegate? 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.action = self 
     newGame() 
    } 

    @IBAction func menuClick(sender: AnyObject) { 
     navigation?.toggleLeftPanel() 
    } 

    func setTitleBarTitle(title: String) { 
     titleBar.title = title 
    } 

    func newGame() { 
     print("skview bounds: \(self.gameView.bounds.size)") 
     let game = GameScene(size: self.gameView.bounds.size) 
     self.game = game 
     game.action = action 
     game.scaleMode = .ResizeFill 
     self.gameView.presentScene(game) 
    } 
} 

Main.storyboard作成する場所です

Constraints

追加コーナーサークル&ボーダーライン

if let scene = self.scene { 
      let dot = SKShapeNode(circleOfRadius: 10) 
      dot.fillColor = UIColor.blueColor() 
      dot.position = CGPoint(x: 0,y: 0) 

      let dot1 = SKShapeNode(circleOfRadius: 10) 
      dot1.fillColor = UIColor.blueColor() 
      dot1.position = CGPoint(x: scene.size.width,y: 0) 

      let dot2 = SKShapeNode(circleOfRadius: 10) 
      dot2.fillColor = UIColor.blueColor() 
      dot2.position = CGPoint(x: 0,y: scene.size.height) 

      let dot3 = SKShapeNode(circleOfRadius: 10) 
      dot3.fillColor = UIColor.blueColor() 
      dot3.position = CGPoint(x: scene.size.width,y: scene.size.height) 


      let left = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 3, height: scene.size.height)) 
      let top = SKShapeNode(rect: CGRect(x: 0, y: scene.size.height, width: scene.size.width, height: 3)) 
      let right = SKShapeNode(rect: CGRect(x: scene.size.width, y: 0, width: 3, height: scene.size.height)) 
      let bottom = SKShapeNode(rect: CGRect(x: 0, y: 0, width: scene.size.width, height: 3)) 

      left.fillColor = UIColor.redColor() 
      top.fillColor = UIColor.redColor() 
      bottom.fillColor = UIColor.redColor() 
      right.fillColor = UIColor.redColor() 


      scene.addChild(dot) 
      scene.addChild(dot1) 
      scene.addChild(dot2) 
      scene.addChild(dot3) 

      scene.addChild(left) 
      scene.addChild(top) 
      scene.addChild(right) 
      scene.addChild(bottom) 
     } 

答えて

1

は、それは私の制約が正しく設定されていないことが判明しました。

制約
ios view constraints

結果
iPhone 4s portrait

関連する問題