SwiftUI - NavigationBarTitleDisplayMode - 根据模式动态更改标题
当视图的 .navigationBarTitleDisplayMode (设置为 .automatic)从 .large 更改为 .inline 或反之亦然时,有没有办法收到通知?
类似 @Environment 对象的东西类似于取决于
@Environment(\.locale) var locale: Locale
显示模式,我想显示不同的标题。
大致如下:
@Environment(\.navigationBarTitleDisplayMode) var mode: NavigationBarTitleDisplayMode
...
.navigationBarTitle(mode == .large ? "I am the large title" : "Inline title")
.navigationBarTitleDisplayMode(.automatic)
Is there a way to get notified when the .navigationBarTitleDisplayMode (which is set to .automatic) of a view changes from .large to .inline or vice versa?
Something like an @Environment object similar to
@Environment(\.locale) var locale: Locale
Depending on the displayMode, I'd like to show a different title.
Something along the lines of:
@Environment(\.navigationBarTitleDisplayMode) var mode: NavigationBarTitleDisplayMode
...
.navigationBarTitle(mode == .large ? "I am the large title" : "Inline title")
.navigationBarTitleDisplayMode(.automatic)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以通过创建您自己的参数来完成。
您可以将此变量传递到环境中并拥有一个全局指示器。
This can be done by creating your own parameter.
You can pass this var into the environment and have a global indicator.