在 RealityKit Swift 应用程序中显示警报后,相机馈送严重失真
我正在制作一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论