I wonder the same. A google search doesn't come up with much.
Post
Replies
Boosts
Views
Activity
I found the only way to get this to work per view is to wrap your rootView in a HostingController like:
class HostingController<ContentView>: UIHostingController<ContentView> where ContentView : View {
init(view: ContentView) {
super.init(rootView: view)
NotificationCenter.default.addObserver(forName: .onDarkStatusBar, object: nil, queue: .main) { _ in
self.statusBarEnterDarkBackground()
}
NotificationCenter.default.addObserver(forName: .onLightStatusBar, object: nil, queue: .main) { _ in
self.statusBarEnterLightBackground()
}
NotificationCenter.default.addObserver(forName: .onShowStatusBar, object: nil, queue: .main) { _ in
self.statusBarShow()
}
NotificationCenter.default.addObserver(forName: .onHideStatusBar, object: nil, queue: .main) { _ in
self.statusBarHide()
}
}
@objc required dynamic init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private var isDarkContentBackground = false
private var isStatusBarHiden = false
func statusBarEnterDarkBackground() {
isDarkContentBackground = false
setNeedsStatusBarAppearanceUpdate()
}
func statusBarEnterLightBackground() {
isDarkContentBackground = true
setNeedsStatusBarAppearanceUpdate()
}
func statusBarHide() {
isStatusBarHiden = true
setNeedsStatusBarAppearanceUpdate()
}
func statusBarShow() {
isStatusBarHiden = false
setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
if isDarkContentBackground {
return .lightContent
}
else
{
return .darkContent
}
}
override var prefersStatusBarHidden: Bool {
return isStatusBarHiden
}
}
Use as
let window = UIWindow(windowScene: windowScene)
window.rootViewController = HostingController(view: contentView)
Then send out a notification from onDissapear and onAppear.
extension Notification.Name {
static let onDarkStatusBar = Notification.Name("onDarkStatusBar")
static let onLightStatusBar = Notification.Name("onLightStatusBar")
static let onHideStatusBar = Notification.Name("onHideStatusBar")
static let onShowStatusBar = Notification.Name("onShowStatusBar")
}
Using
.onAppear {
NotificationCenter.default.post(name: Notification.Name.onHideStatusBar, object: nil)
}
.onDisappear {
NotificationCenter.default.post(name: Notification.Name.onShowStatusBar, object: nil)
}
Is there any workaround, also seeing this issue?
Works a treat, thanks a lot. Of stuck on this for some hours.
So I'mon iOS 16.3 and this issue seems to still be here. Did anyone find any solution to this?
Specifically I'm doing
private let camera = PerspectiveCamera()
camera.camera.fieldOfViewInDegrees = cameraFieldOfVewInDegrees
let cameraAnchor = AnchorEntity(world: .zero)
cameraAnchor.addChild(camera)
arView?.scene.addAnchor(cameraAnchor)