在 RealityKit Swift 应用程序中显示警报后,相机馈送严重失真

发布于 2025-01-17 09:55:47 字数 1129 浏览 0 评论 0原文

我正在制作一个 RealityKit 应用程序,并且刚刚添加了以下警报功能 这篇文章。警报是由执行一些计算的结构触发的,特别是在 guard let 语句的 else 子句中:

guard let example = ... else {     
    DispatchQueue.main.asyncAfter(deadline: .now()) {
        NotificationCenter.default.post(name: SomeClass.showAlertMsg, object: nil)
    }
}

AR 应用程序的相机源最初显示良好,但是一旦上述片段触发警报,提要就会严重失真。即使消除警报后,提要仍然失真并且基本上无法使用。有没有办法在警报解除后防止失真发生或重置摄像机源/AR 视图?

如果重要的话,失真似乎是摄像机馈送旋转 90 度和沿屏幕垂直拉伸的组合。

编辑:这是设置警报的 ContentView

import SwiftUI

struct ContentView : View {
    @State private var showingError = false
    var body: some View {
        Zstack {
            //some unrelated things here
        }.alert("Error message", isPresented: $showingError) {
            Button("Dismiss", role: .cancel) {self.showingError = false}
        }.onReceive(NotificationCenter.default.publisher(for: someClass.showAlertMsg)) {msg in 
            self.showingError = true
        }
    }
}

I am making a RealityKit app, and just added an alert functionality following this post. The alert is being triggered from a struct doing some calculations, specifically in the else clause of a guard let statement:

guard let example = ... else {     
    DispatchQueue.main.asyncAfter(deadline: .now()) {
        NotificationCenter.default.post(name: SomeClass.showAlertMsg, object: nil)
    }
}

The camera feed for the AR app shows up fine initially, but as soon as the alert is triggered from the above segment the feed gets heavily distorted. Even after dismissing the alert the feed remains distorted and essentially unusable. Is there a way to either prevent the distortion from occurring or to reset the camera feed/AR view after the alert is dismissed?

If it matters, the distortion seems to be a combination of the camera feed rotating 90 degrees and stretching vertically along the screen.

EDIT: Here is the ContentView where the alert is set up:

import SwiftUI

struct ContentView : View {
    @State private var showingError = false
    var body: some View {
        Zstack {
            //some unrelated things here
        }.alert("Error message", isPresented: $showingError) {
            Button("Dismiss", role: .cancel) {self.showingError = false}
        }.onReceive(NotificationCenter.default.publisher(for: someClass.showAlertMsg)) {msg in 
            self.showingError = true
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文