我正在使用故事板创建一个UIVIEw,以及一个SKVIEw的子视图.我想以编程方式创建一个SKS的尺寸SKScene.
我的想法是scene.size.height和scene.size.wIDth将等于SKVIEw的高度和宽度.为了测试这个,我在每个角落绘制了四个蓝色圆圈,并在边框上绘制了红线.当我期待看到所有四个蓝色角点和边界线时,我只能看到左下角.
请忽略场景中的黑色圆圈,它们无关紧要.
iPhone 6截图(肖像)
iPhone 6截屏(风景)
我添加了SW(西南),SE,NE和NW标签
VIEwController与SKVIEw参考
这是我创建SKSCene的地方(参见func newGame)
import UIKitimport SpriteKitclass 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
约束
添加角落圆圈&边界线
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,height: scene.size.height)) let bottom = SKShapeNode(rect: CGRect(x: 0,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) }解决方法 事实证明我的约束没有正确设置.
约束
结果
以上是内存溢出为你收集整理的ios – 如何正确调整SKView子视图和SKScene的大小全部内容,希望文章能够帮你解决ios – 如何正确调整SKView子视图和SKScene的大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)