简体   繁体   English

列表边缘插图不断变化 - SwiftUI

[英]List edge insets keeps changing - SwiftUI

I have a SwiftUI app that uses a sidebar on iPad.我有一个在 iPad 上使用侧边栏的 SwiftUI 应用程序。

Using a List with the modifier .listStyle(.sidebar) the inset spacing no longer applies when rotating, however when I force close the app and reopen it appears normal.使用带有修饰符.listStyle(.sidebar)List ,旋转时插入间距不再适用,但是当我强制关闭应用程序并重新打开它时,它看起来很正常。

Cases where edge spacing no longer applies:边缘间距不再适用的情况:

  • When user first signs in当用户首次登录时
  • rotates device旋转装置
  • collapses sidebar and reopens)折叠侧边栏并重新打开)

在此处输入图像描述

The problem goes away when force quitting the app and reloading when user is signed in.当用户登录时强制退出应用程序并重新加载时,问题就消失了。

在此处输入图像描述

ContentView内容视图

struct ContentView: View {
   @State var signedIn = false

    var body: some View {
        if signedIn = false  {
            Text("Sign In").onTapGesture(){signedIn = true}
        } 
        if signedIn = true {
            AppSidebarNavigation()
        }
    }
}

Sidebar侧边栏

struct AppSidebarNavigation: View {
    
    enum NavigationItem {
        case home
        case expenses
    }
        
    @State private var selection: NavigationItem? = .home

    var body: some View {
        NavigationView {
            sidebar
                .navigationTitle("")
                .navigationBarTitleDisplayMode(.inline)
                .navigationBarHidden(true)
            
            // Main View
            HomeView()
            
        }
        .navigationViewStyle(DoubleColumnNavigationViewStyle())

    }
}

extension AppSidebarNavigation {
    
    var sidebar: some View {
            List(selection: $selection) {
                Group {
                    NavigationLink(destination: HomeView()
                        .environmentObject(store), tag: NavigationItem.home, selection: $selection) {
                            Label("Homes", systemImage: "house")
                            
                        }
                        .tag(NavigationItem.home)
                    
                    NavigationLink(destination: Expenses(),
                        tag: NavigationItem.expenses, selection: $selection) {
                            Label("Expenses", systemImage: "arrow.right.arrow.left")
                            
                        }
                        .tag(NavigationItem.expenses)
                        .navigationBarTitleDisplayMode(.large)
                }

            }
            .listStyle(.sidebar)
    }
}

So I would consider trying所以我会考虑尝试

.listRowInsets(EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8))

or或者

.listRowInsets(EdgeInsets())

Even add甚至添加

.listRowInsets(.init())

However your problem may be due to your subviews overriding TableView rows.但是,您的问题可能是由于您的子视图覆盖了 TableView 行。 Check if you have something like (I am not sure the exact code)检查您是否有类似的东西(我不确定确切的代码)

init() {

    UITableViewCell.removeEdgeInsets

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift UIButton 边缘嵌件 - Swift UIButton edge insets UICollectionView横向模式下不正确的边缘插图 - UICollectionView incorrect edge insets in landscape mode UICollectionViewDelegateFlowLayout Edge嵌入无法被sizeForItemAt函数识别? - UICollectionViewDelegateFlowLayout Edge Insets not getting recognized by sizeForItemAt function? 如何在视图的右边缘对齐和锚定 SwiftUI 水平列表? - How to align and anchor SwiftUI horizontal list at right edge of view? 更改特定列表元素 SwiftUI 的颜色 - Changing the colour of specific list elements SwiftUI 在 iOS 上,边距、边缘插入、内容插入、对齐矩形、布局边距、锚点……之间有什么区别? - On iOS, what are the differences between margins, edge insets, content insets, alignment rects, layout margins, anchors…? 导航控制器内的TableView:左侧和右侧的零边缘插图? - TableView inside Navigation Controller: Zero Edge Insets on the Left and on the Right? SwiftUI 中 VStack 的前沿 - leading edge for VStack in SwiftUI 显示键盘时更改UITableView插入的问题 - Problems changing UITableView insets when keyboard its showed 从列表中选择多个项目并在 SwiftUI 中更改它们的颜色 - selecting multiple items from the list and changing their color in SwiftUI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM