![](/img/trans.png)
[英]How to show Profile Icon next to Large Navigation Bar Title in SwiftUI?
[英]SwiftUI - How to programatically scroll to top and show a large navigation title?
最近添加到 iOS 14 ScrollViewReader
添加了一种以编程方式滚动到 SwiftUI 中的视图的方法。
问:有没有一种方法可以滚动到 ScrollView 中最顶层的元素并显示一个大的导航标题?
预期效果:滚动到顶部后的大导航标题
代码片段供参考:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollViewReader { proxy in
ScrollView {
Rectangle()
.fill(.yellow)
.aspectRatio(contentMode: .fit)
.id("scrollID")
Rectangle()
.fill(.blue)
.aspectRatio(contentMode: .fit)
Rectangle()
.fill(.green)
.aspectRatio(contentMode: .fit)
Rectangle()
.fill(.red)
.aspectRatio(contentMode: .fit)
Button("Scroll to top") {
withAnimation {
proxy.scrollTo("scrollID")
}
}
}
.navigationTitle("Navigation")
}
}
}
}
此代码滚动到按钮点击时的顶部矩形,但它不会显示默认的大导航标题。 我怎样才能做到这一点?
(我还没有测试过:)尝试:
showLargeDisplayMode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.