问题描述
下面的代码显示 SKView
,直到将 skHeight
更改为2050或更高的值(如5000)为止.
1)即使在2050或5000的高度下,如何显示 SKView
?
2) SKViews
的最大大小是多少?
要复制:
1)运行以下代码.您会看到 SKView
表示为灰色窗口.
2)将 skHeight
更改为2050或5000. SKView
不再显示.
TestTestController类:UIViewController {覆盖func viewDidLoad(){super.viewDidLoad()//创建SKView让skHeight = CGFloat(2050)让skFrame = CGRect(x:0,y:0,宽度:100,高度:skHeight)让skView = SKView(frame:skFrame)skView.backgroundColor = UIColor.red//将测试视图添加到< scrollView>view.addSubview(skView)}}
在许多设备上,OpenGL渲染不支持大于4096x4096的画布大小,您的视图为2050x2050,因此,如果将视网膜模式考虑在内,它的大小实际上为4100x4100./p>
@ 3x设备现在变得更加疯狂,因为它需要处理硬件的缩放和缩小,因此最终只能获得约1501x1501的视图.
金属不存在此问题,从iOS 12开始,不建议使用OpenGL,因此希望模拟器也将使用金属.(这应该是因为Mojave仅支持金属设备)
The code below shows a SKView
until you change skHeight
to 2050 or some higher value like 5000.
1) How can you make the SKView
appear even at heights of 2050 or 5000?
2) What's the maximum size for SKViews
?
To reproduce:
1) Run the code below. You will see the SKView
represented as a gray window.
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 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.
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 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的最大高度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!