本文介绍了如何在 SwiftUI NavigationLink 中移除不透明动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
点击 NavigationLink 时,它会略微降低不透明度.有没有办法禁用它.我尝试使用 .buttonStyle(PlainButtonStyle())
但这没有达到预期的效果.
When tapping on a NavigationLink, it reduces the opacity slightly. Is there a way to disable this. I tried using .buttonStyle(PlainButtonStyle())
but that didn't have the desired effect.
它嵌入在滚动视图中(为了可定制性,优先于列表):
It is embedded in a scrollView (preferred over List for customizability):
ScrollView {
ForEach(items){ item in
NavigationLink(destination: DetailView()){
HStack{
Text("title")
Spacer()
Image(systemName: "chevron.right")
}
.padding()
.background(
RoundedRectangle(cornerRadius: 10, style: continuous)
.foregroundColor(Color.gray)
)
}
}
}
推荐答案
这里是可能的解决方案.使用 Xcode 11.4/iOS 13.4 测试
Here is possible solution. Tested with Xcode 11.4 / iOS 13.4
使用只返回标签视图的自定义按钮样式(无高亮效果)
Use custom button style that just returns label view (w/o highlight effect)
struct FlatLinkStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
}
}
和
NavigationLink(destination: DetailView()){
HStack{
Text("title")
Spacer()
Image(systemName: "chevron.right")
}
.padding()
}.buttonStyle(FlatLinkStyle()) // << here !!
这篇关于如何在 SwiftUI NavigationLink 中移除不透明动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!