升级至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
相关产品推荐
相关产品推荐

