In SwiftUI, I understand that modifiers are used to modify a view. When modifying a view, the modifier returns the view wrapped in _ModifiedContent.
When embedding my view inside a NavigationView and assigning a navigation bar title like this: (as seen in Apple's official tutorials)
NavigationView {
Text("Hello, World!")
.navigationBarTitle(Text("My first SwiftUI App"))
}
Run Code Online (Sandbox Code Playgroud)
...why is the modifier for the navigation bar title applied to Text, not to NavigationView?
就像马丁链接到的一样,navigationBarTitle只有当包含在里面时才有效NavigationView。SwiftUI Essentials演讲中约52:30对此进行了简要讨论。标题最终流向NavigationView,因此被推送的视图也可以提供自己的标题(例如,在〜54:00被推送的视图)。
如果标题NavigationView直接附加到标题上,则需要预先确定所有可能的标题,并将其从与标题关联的视图中删除。
它与UIViewController的navigationItem属性相似,该属性附加在每个推入视图中,而不是附加在其UINavigationController本身上。
| 归档时间: |
|
| 查看次数: |
586 次 |
| 最近记录: |