首页 > 解决方案 > 在 SwiftUI 中展开时,NSOutlineView 不会改变高度

问题描述

我用 NSViewRepresentable 包装了一个 NSOutlineView,效果很好。问题是当一个项目展开时,大纲视图不会改变高度并且动画不能正常工作(见下面的 gif)。当我将大纲视图放在 NSScrollView 中时,它可以正常工作,但我需要能够在单个 SwiftUI 滚动视图中放置多个大纲视图。

struct Test: View {
    var body: some View {
        ScrollView {
            SwiftUiOutline()
            // Ultimately I need multiple outline views here
        }
    }
}

struct SwiftUiOutline: NSViewRepresentable {
    func makeNSView(context: Context) -> NSOutlineView {
        let view = NSOutlineView()

        // Outline view is set up here, and connected to the coordinator delegate

        return view
    }

    class Coordinator: CustomOutlineViewController {
        // The coordinator handles all the outline view delegation, etc.
    }

    // ...
}

问题:

在此处输入图像描述

它应该如何工作:

在此处输入图像描述

任何帮助,将不胜感激!

标签: swiftmacoscocoaswiftuinstableview

解决方案


推荐阅读