微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何防止工作表在SwiftUI中变暗或隐藏不必要的填充?

如何解决如何防止工作表在SwiftUI中变暗或隐藏不必要的填充?

SwiftUI sheet darkens the view behind it and leaves padding around the view

显示工作表(模态)时,其后面的视图会缩小并变暗,从而在工作表后产生一个灰色矩形(请参见图片中红色框内的位)。如何防止背景中的视图变暗或在视图缩小时摆脱周围的白色填充?

解决方法

这是默认的.sheet行为。

对于 SwiftUI 2.0 ,请改用全屏封面

@available(iOS 14.0,tvOS 14.0,watchOS 7.0,*)
@available(macOS,unavailable)
extension View {

    /// Presents a modal view that covers as much of the screen as
    /// possible using the given item as a data source for the sheet's content.
    ///
    /// - Parameters:
    ///   - item: A binding to an optional source of truth for the cover
    ///     modal view. When representing a non-nil item,the system uses
    ///     `content` to create a modal representation of the item.
    ///     If the identity of `item` changes,the system will dismiss a
    ///     currently-presented modal view and replace it by a new modal view.
    ///   - onDismiss: A closure executed when the modal view dismisses.
    ///   - content: A closure returning the content of the modal view.
    public func fullScreenCover<Item,Content>(item: Binding<Item?>,onDismiss: (() -> Void)? = nil,@ViewBuilder content: @escaping (Item) -> Content) -> some View where Item : Identifiable,Content : View


    /// Presents a modal view that covers as much of the screen as
    /// possible when a given condition is true.
    ///
    /// - Parameters:
    ///   - isPresented: A binding to whether the modal view is presented.
    ///   - onDismiss: A closure executed when the modal view dismisses.
    ///   - content: A closure returning the content of the modal view.
    public func fullScreenCover<Content>(isPresented: Binding<Bool>,@ViewBuilder content: @escaping () -> Content) -> some View where Content : View

}

对于 SwiftUI 1.0 ,您可以使用过渡功能以全屏显示视图,请参见https://stackoverflow.com/a/61446820/12299030

中的示例

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。