【发布时间】:2018-04-12 02:23:12
【问题描述】:
我有一个在 SpriteKit 中构建的游戏,我正在尝试为 iPhone X 调整它的大小。
这是我的初始设置代码:
override func viewDidLoad() {
super.viewDidLoad()
authenticateLocalPlayer()
var isiphonex = false
if UIDevice().userInterfaceIdiom == .phone {
if UIScreen.main.nativeBounds.height == 2436{
isiphonex=true
}
}
let skView = self.view as! SKView
if(isiphonex){
if #available(iOS 11.0, *) {
print("ios11")
skView.frame = CGRect(x: 39 , y: 0, width: 667, height: skView.safeAreaLayoutGuide.layoutFrame.height)
} else {
// Fallback on earlier versions
}
}
let startScene = StartScene(size:skView.bounds.size)
startScene.anchorPoint = CGPoint(x: 0.0892857, y: 0)
skView.showsFPS = false
skView.showsNodeCount = false
skView.ignoresSiblingOrder = true
startScene.scaleMode = .resizeFill
skView.presentScene(startScene)
}
然后当场景加载时我这样做:
override func didMove(to view: SKView) {
print(scene?.size.width)
print(view.bounds.size.width)
print(scene!.view!.bounds.size.width)
}
它们都打印 667
但是当我试图在触摸过程中改变场景并这样做时:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
print(scene!.size.width)
print(scene!.view!.bounds.size.width)
}
他们都打印 812。
为什么会这样,我怎样才能让它保持在 667?
【问题讨论】:
标签: ios xcode uiview sprite-kit skscene