问题
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