gpt4 book ai didi

ios - UIScreen.main.bounds 返回什么值?屏幕尺寸匹配问题

转载 作者:行者123 更新时间:2023-11-30 12:46:12 29 4
gpt4 key购买 nike

文档和其他指南向我建议,Swift 中的 UIScreen.main.bounds 返回屏幕的边缘。然而,在 Swift 中使用模拟器时,情况并非如此。

下面是使用相同代码的 XCode 模拟器(5s、6)的两个屏幕截图。

iPhone5s iPhone6

代码如下,但本质上只是用坐标(screenwidth,screenheight),(-screenwidth,screenheight),(screenwidth,-screenheight),(-screenwidth,-screenheight)绘制四个路径。

我是否误解了 UIScreen.main.bounds?或者还有其他什么原因导致这种情况吗?理想情况下,我希望能够以编程方式设置找到屏幕四个角的变量。

这一切都是在 GameScene 中完成的。我没有在 Storyboard上添加任何功能。

    let screenSize = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
let pathBound = UIBezierPath(rect: CGRect(x: -screenWidth, y: -screenHeight, width: 5, height: screenHeight*2))
let shapeNode = SKShapeNode(path: pathBound.cgPath)
shapeNode.fillColor = UIColor.green
shapeNode.strokeColor = UIColor.green
addChild(shapeNode)
let pathBound2 = UIBezierPath(rect: CGRect(x: screenWidth-5, y: -screenHeight, width: 5, height: screenHeight*2))
let shapeNode2 = SKShapeNode(path: pathBound2.cgPath)
shapeNode2.fillColor = UIColor.blue
shapeNode2.strokeColor = UIColor.blue
addChild(shapeNode2)
let pathBound3 = UIBezierPath(rect: CGRect(x: -screenWidth, y: screenHeight-5, width: screenWidth*2, height: 5))
let shapeNode3 = SKShapeNode(path: pathBound3.cgPath)
shapeNode3.fillColor = UIColor.red
shapeNode3.strokeColor = UIColor.red
addChild(shapeNode3)
let pathBound4 = UIBezierPath(rect: CGRect(x: -screenWidth, y: -screenHeight, width: screenWidth*2, height: 5))
let shapeNode4 = SKShapeNode(path: pathBound4.cgPath)
shapeNode4.fillColor = UIColor.orange
shapeNode4.strokeColor = UIColor.orange
addChild(shapeNode4)
let pathBound5 = UIBezierPath(rect: CGRect(x: -screenWidth, y: 0
, width: screenWidth*2, height: 5))
let shapeNode5 = SKShapeNode(path: pathBound5.cgPath)
shapeNode5.fillColor = UIColor.purple
shapeNode5.strokeColor = UIColor.purple
addChild(shapeNode5)

最佳答案

你对此有何看法-

var screenWidth = UIScreen.main.bounds.size.width


var screenHeight = UIScreen.main.bounds.size.height

关于ios - UIScreen.main.bounds 返回什么值?屏幕尺寸匹配问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41606607/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com