问题描述
下面的代码显示 SKView
,直到您将 skHeight
更改为 2050 或更高的值,例如 5000.
The code below shows a SKView
until you change skHeight
to 2050 or some higher value like 5000.
1) 如何让 SKView
出现在 2050 或 5000 的高度?
1) How can you make the SKView
appear even at heights of 2050 or 5000?
2) SKViews
的最大尺寸是多少?
2) What's the maximum size for SKViews
?
重现:
1) 运行以下代码.您将看到 SKView
显示为灰色窗口.
1) Run the code below. You will see the SKView
represented as a gray window.
2) 将 skHeight
更改为 2050 或 5000.SKView
不再出现.
2) Change skHeight
to 2050 or 5000. The SKView
no longer appears.
class TestViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Create SKView
let skHeight = CGFloat(2050)
let skFrame = CGRect(x: 0, y: 0, width: 100, height: skHeight)
let skView = SKView(frame: skFrame)
skView.backgroundColor = UIColor.red
// Add test view to <scrollView>
view.addSubview(skView)
}
}
推荐答案
OpenGL 渲染在很多设备上不支持大于 4096x4096 的画布,你的视图是 2050x2050,所以当你考虑视网膜模式时,它真的变成了 4100x4100.
OpenGL rendering does not support canvas sizes greater than 4096x4096 on many devices, your view is 2050x2050, so when you factor in retina mode, it really becomes 4100x4100.
现在@3x 设备更加疯狂,因为它需要处理硬件缩放和收缩,所以您最终只能获得大约 1501x1501 的视图.
Now the @3x devices are even crazier, because it needs to handle the hardware scaling and shrinking, so you only end up getting views of about 1501x1501.
Metal 没有这个问题,从 iOS 12 开始,OpenGL 已被弃用,因此希望模拟器也能使用 Metal.(应该是因为 Mojave 只支持金属设备)
Metal does not have this problem, and as of iOS 12, OpenGL is deprecated, so hopefully the Simulators will be using Metal as well. (It should since Mojave only supports metal devices)
这篇关于SpriteKit:为什么SKView在一个高度消失,却在另一个高度出现?SKView 的最大高度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!