如何将复杂的Uikit视图转换为Swiftui视图?
这里有很多代码,但是请耐心等待我要解释我的问题
,所以我试图转换苹果的avdepthcapture项目,该项目在Uikit中为SwiftUi项目,因此我复制了所有支持文件,我将附加图像下面相同的是,着色器文件夹包含用于应用过滤器的金属文件
因此我创建了一个与cameraviewController相同的类,并添加了所有属性,如下所示 -
class CameraViewController: UIViewController, AVCapturePhotoCaptureDelegate, AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureDepthDataOutputDelegate, AVCaptureDataOutputSynchronizerDelegate, ObservableObject {
private var previewView: PreviewMetalView!
} 现在,当我在设备上运行应用程序时,它要求获得相机许可,但随后显示一个白屏,而不是打开相机和我直接从原始Uikit项目中复制的PreviewMetalView文件, 该声明引起了
private var previewView: PreviewMetalView!
这一行错误,它退出了我的应用程序,并说在解开可选值时出乎意料地发现了零,但是代码与Uikit Project和Uikit Project的代码相同,而Uikit Project则在我的设备上效果很好,那么为什么会抛出此错误!
现在,PreviewMetalView具有一个初始评估器,该初始评估属于NScoder类型,所以我应该在那里写什么? 就像我会宣布我的变量为 var PreviewView = PreviewMetalView(编码器:nscoder) 什么可以代替NScoder?
当我打开原始Uikit项目时,PreviewView被定义为具有容器视图的IBOUTLET,然后将其链接到CameraviewController,但我找不到在哪里初始化的地方请帮助!
there's a lot of code in here but please be patient I will try to explain my question
so i am trying to convert Apple's AvDepthCapture project which is in UIKit as a SwiftUI project, so i copied all the supporting files, i will attach the image for the same below, the shaders folder contain the metal files for applying filters
so I created a class same as the cameraviewcontroller and added all the properties as follows -
class CameraViewController: UIViewController, AVCapturePhotoCaptureDelegate, AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureDepthDataOutputDelegate, AVCaptureDataOutputSynchronizerDelegate, ObservableObject {
private var previewView: PreviewMetalView!
}
now when i run my app on my device it asks for camera permission but then shows a white screen instead of opening the camera and the PreviewMetalView file that i copied earlier directly from the original UIKit project,
the declaration is causing error
private var previewView: PreviewMetalView!
this line, it quits my app and says unexpectedly found nil when unwrapping an optional value but the code is the same as that of the UIKit project and UIKit project works perfectly fine on my device then why is it throwing this error!?, please help i can provide both the UIKit project and my SwiftUI project file if you want to see i really can't figure it out
there's a lot of code but this specific line is throwing error, I declared a type of PreviewMetalView but now PreviewMetalView has an initialiser which takes in a type NSCoder so what should I write there ??
like I would be declaring my variable as
var previewView = PreviewMetalView(coder: NSCoder)
what to put in place of NSCoder ?
when I opened the original UIKit project the previewView is defined as an IBOutlet to a Container View which is then linked to the CameraViewController but I cannot find where is it initialised please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论