Я представляю представление SwiftUI с использованием UIHostingController с modalPresentationStyle = .overCurrentContext. Внутри этого корневого представления SwiftUI я представляю .sheet со специальным модификатором, делающим фон листа прозрачным.
Минимальный воспроизводимый код:
struct SheetContent: View {
var body: some View {
VStack(spacing: 0) {
// This image should sit behind the home indicator
Image(systemName: "star.fill")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxWidth: .infinity)
}
// This makes the background transparent, but the bottom safe area
// still clips the Red background/Image above.
// .ignoresSafeArea(.all) //
Подробнее здесь: [url]https://stackoverflow.com/questions/79851613/how-to-ignoresafearea-when-presenting-content-in-swiftui-sheet[/url]
Я представляю представление SwiftUI с использованием UIHostingController с modalPresentationStyle = .overCurrentContext. Внутри этого корневого представления SwiftUI я представляю .sheet со специальным модификатором, делающим фон листа прозрачным. Минимальный воспроизводимый код: [code]import SwiftUI
class SheetViewModel: ObservableObject { @Published var isPresented: Bool = true }
struct RootSheetWrapper: View { @StateObject var viewModel: SheetViewModel
var body: some View { // Transparent host view acting as the anchor for the sheet Color.clear .customTransparentSheet(isPresented: $viewModel.isPresented, height: 400) { SheetContent() } } }
private extension View { @ViewBuilder func applyTransparentBackground() -> some View { if #available(iOS 16.4, *) { self.presentationBackground(.clear) } else { self.background(Color.clear.ignoresSafeArea()) } } } [/code] Содержимое листа: [code]struct SheetContent: View { var body: some View { VStack(spacing: 0) { // This image should sit behind the home indicator Image(systemName: "star.fill") .resizable() .aspectRatio(contentMode: .fill) .frame(maxWidth: .infinity) } // This makes the background transparent, but the bottom safe area // still clips the Red background/Image above. // .ignoresSafeArea(.all) //