You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级至Xcode 26后UIDropShadow部分遮挡.sheet视图问题

解决Xcode 16+中SwiftUI自定义Sheet出现UIDropShadowView遮挡问题

升级到Xcode 16之后,SwiftUI的Sheet组件底层视图结构有调整,原来设置presentationBackground(.clear)已经无法完全移除系统默认的UIDropShadowView,导致它遮挡后方内容。可以尝试以下几种解决方案:

  • 替换背景设置API:用presentationBackgroundStyle(.clear)替代原来的presentationBackground(.clear),这个API在iOS 17+(对应Xcode 16)能更精准控制Sheet的背景样式,包括阴影层:
someView
    .sheet(isPresented: $showPuppyList) {
        MyCustomView()
            .presentationBackgroundStyle(.clear)
            .onDisappear(){
                self.showBlurView = false
                self.userData = Utility.getUserData()
            }
    }
  • 配合圆角设置:如果单独设置背景样式无效,加上presentationCornerRadius(0),系统的阴影视图有时会和圆角绑定,移除圆角后可能会隐藏阴影:
someView
    .sheet(isPresented: $showPuppyList) {
        MyCustomView()
            .presentationBackgroundStyle(.clear)
            .presentationCornerRadius(0)
            .onDisappear(){
                self.showBlurView = false
                self.userData = Utility.getUserData()
            }
    }
  • 固定Sheet高度:通过presentationDetents指定Sheet的高度,让系统Sheet完全贴合你的自定义视图,减少额外视图生成的可能:
someView
    .sheet(isPresented: $showPuppyList) {
        MyCustomView()
            .presentationBackgroundStyle(.clear)
            .presentationDetents([.height(300)]) // 替换为你的自定义视图实际高度
            .onDisappear(){
                self.showBlurView = false
                self.userData = Utility.getUserData()
            }
    }

另外可以检查你的MyCustomView,把最外层的透明遮罩(Color.mint.opacity(0.0101))替换为Color.clear,避免意外触发系统额外的背景渲染。

内容的提问来源于stack exchange,提问作者dextra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 16:32:40