简体   繁体   中英

How to make edgesIgnoringSafeArea in swiftUI work?

The following code makes a view where a rectangle is at the bottom of the view. I put.edgesIgnoringSafeArea(.bottom) so the rectangle goes all the way down but it doesn't work. Im simulating this on an Iphone 11 and always leaves a blank space below.

struct ContentView: View {
    var body: some View {
        NavigationView {
            VStack {
                List {
                    Text("Hello, World!")
                }
                
                Spacer()
                
                Rectangle()
                    .frame(height: 150)
                    .edgesIgnoringSafeArea(.bottom)
            }
        }
    }
}

在此处输入图像描述

The rectangle is inside a VStack , and the VStack doesn't ignore the safe area. Even if the rectangle ignores the safe area, it can't extend beyond its parent to fill the whole screen.

You should put edgesIgnoringSafeArea after the VStack , and the rectangle will naturally fill the VStack , hence filling the whole screen.

var body: some View {
    NavigationView {
        VStack {
            List {
                Text("Hello, World!")
            }
            
            Spacer()
            
            Rectangle()
                .frame(height: 150)
        }
        .edgesIgnoringSafeArea(.bottom)
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM