The only thing to do in this case is to use the custom title view in the navigation bar, and not use the default navigation title at all.
NavigationView {
YourView()
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Text("Title").opacity(titleOpacity)
}
}
}
You will need to calculate the value of titleOpacity
yourself by observing the offset value of the scroll view, and adjusting the parameters accordingly.
@State private var scrollOffset: CGFloat = 0
private var titleOpacity: Double {
// calculate the opacity based of current scroll view offset
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…