How to clip ARSCNView bounds to circle?

纵饮孤独 提交于 2019-12-11 18:43:38

问题


Should be straightforward to clip an ARSCNView since ARSCNView is a subclass of UIView.

After boilerplate (sceneView.session.run(configuration)) logic, adding a scene view programmatically works in the ViewController:

sceneView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(sceneView)

NSLayoutConstraint.activate([
    sceneView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1.0),
    sceneView.heightAnchor.constraint(equalTo: sceneView.widthAnchor, multiplier: 1.0),
    sceneView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
    sceneView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])

The sceneView shows up as a square.

However, adding the clipping/mask doesn't work.

sceneView.layer.masksToBounds = true
sceneView.clipsToBounds = true
sceneView.layer.cornerRadius = UIScreen.main.bounds.width/2

What happens is the sceneView is still a square.

Oddly enough, when the app starts (or view did load), the clipping works so the sceneView is a circle. Also, when I exit the app, the snapshot of the app shows the sceneView as a circle. What's more, when I turn on iOS screen video recording, the sceneView shows as a circle.

This seems like a bug to me? The sceneView shows without clipping when run normally. However, when the sceneView is entering/exiting (or memory constrained), it shows as a circle (as intended).

Has anyone run into this and knows how to fix? Or should we file a radar. Thanks!

来源:https://stackoverflow.com/questions/54922139/how-to-clip-arscnview-bounds-to-circle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!