通过点击/水龙头以基础uiviewermesenterable

发布于 2025-01-26 03:48:22 字数 1930 浏览 4 评论 0原文

我有一个uiviewRementable,我正在使用uiview s和swiftui创建的混合项目。

我的视图是全屏幕,我的问题是,我找不到一种通过屏幕顶部的透明uinavigationbar传递给我的基础uiview的方法。这意味着,即使可见,前100个左右的像素也不会响应触摸。我已经看过这篇文章和解决方案,但在我的情况下它不起作用。我相信这是因为我正在使用uiviewRementable

对于我的内容视图,我有:

struct ContentView: View {
    let values: [String] = ViewType.allCases.map { "\($0.rawValue)" }
    var body: some View {
        
        NavigationView {
            List {
                ForEach(values, id: \.self) { value in
                    NavigationLink(value, destination: CustomView(viewName: value).ignoresSafeArea())
                }
                .navigationTitle("Nav Title")
            }
        }
        .accentColor(.white)
    }
}

struct CustomView: UIViewRepresentable {
    let viewType: String
    
    func makeUIView(context: Context) -> CustomView {
        CustomView(view: viewType)
    }
    
    func updateUIView(_ view: CustomView, context: Context) {
        view.draw(view.frame)
    }
}

这是我的视图层次结构的图像,显​​示uinavigationbar阻止我的基础uiview的前100个像素> uiview 并防止触摸被注册从视图中。

我知道我可以禁用导航栏,但确实可以使用,但是我确实需要返回按钮。理想情况下,我想了解我如何应用上面链接到上面的解决方案,除非有uicontrol

更新

我尝试了Asperi使用透明度的建议,然后禁用导航栏,我想到用它禁用IT的IT残障来检查视图调试器。

事实证明,返回按钮仍在视图层次结构中,但是当禁用导航栏时,在应用程序中不可见。如果有一种方法可以使NAV栏禁用但可以启用按钮,那将是理想的情况。

I have a UIViewRepresentable that I am using the blend a project created with UIViews and SwiftUI.

My views are full screen and my issue is that I cannot find a way to pass touches through the transparent UINavigationBar at the top of the screen to my underlying UIView. That means that the top 100 or so pixels don't respond to touch even though they're visible. I have seen this post and solution, but it does not work in my case. I believe it's because I'm using UIViewRepresentable.

For my content view I have:

struct ContentView: View {
    let values: [String] = ViewType.allCases.map { "\($0.rawValue)" }
    var body: some View {
        
        NavigationView {
            List {
                ForEach(values, id: \.self) { value in
                    NavigationLink(value, destination: CustomView(viewName: value).ignoresSafeArea())
                }
                .navigationTitle("Nav Title")
            }
        }
        .accentColor(.white)
    }
}

struct CustomView: UIViewRepresentable {
    let viewType: String
    
    func makeUIView(context: Context) -> CustomView {
        CustomView(view: viewType)
    }
    
    func updateUIView(_ view: CustomView, context: Context) {
        view.draw(view.frame)
    }
}

Here is an image of my view hierarchy that shows the UINavigationBar blocking the top 100 or so pixels of my underlying UIView and preventing touches from being registered by the view.

I know I can disable the navigation bar and that does work, but I do need the back button. Ideally, I'd like to understand how I can apply the solution I linked to above which will pass touches unless there is a UIControl in the way.

Image of view hierarchy showing UINavigationBar blocking underlying UIView.

UPDATE

I tried Asperi's suggestion of using transparency and then disabling the navigation bar and it occurred to me to check the view debugger with it disabled.

It turns out that the back button is still there in the view hierarchy, but it is not visible in the app when the nav bar is disabled. If there were a way to keep the nav bar disabled but enable the button, that would be the ideal situation.

Button in debug view without UINavigationBar

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

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

发布评论

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