大佬教程收集整理的这篇文章主要介绍了ios – 如何正确调整SKView子视图和SKScene的大小,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用故事板创建一个UIView,以及一个SKView的子视图.我想以编程方式创建一个SKS的尺寸SKScene.
我的想法是scene.size.height和scene.size.width将等于SKView的高度和宽度.为了测试这个,我在每个角落绘制了四个蓝色圆圈,并在边框上绘制了红线.当我期待看到所有四个蓝色角点和边界线时,我只能看到左下角.
请忽略场景中的黑色圆圈,它们无关紧要.
ViewController与SKView参考
这是我创建SKSCene的地方(参见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) } }@H_276_5@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的大小所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。