swiftui将视图添加到导航视图
我目前正在研究将VoIP应用程序从Uikit重写为Swiftui。在UIKIT版本中,我们有一个带有一个按钮的活动呼叫屏幕,该按钮在敲击时关闭活动的呼叫屏幕,并让您与应用程序进行交互。点击此按钮还向Uinavigation Controller添加了一个视图,基本上涵盖了大多数导航视图,并且在敲击时,将用户返回到活动的呼叫屏幕。
我在Swiftui中尝试了不同的想法,但尚未达到任何扎实的想法,并想看看社区是否有任何实现这一目标的想法。
这是Uikit代码的示例:
class MainNavController: UINavigationController {
func showActiveCallBar() {
...
let activeCallBarView = ...
...
view.addSubview(activeCallBarView)
}
}
这是我们来回切换时发生的事情的GIF,对不起,无法显示整个应用程序。您可以看到涵盖导航视图的整个上部。
谢谢!
I'm currently working on rewriting a VoIP app from UIKit to SwiftUI. In the UIKit version, we have an active call screen with a button that when tapped, closes the active call screen and lets you interact with the app. Tapping this button also adds a view to the UINavigationController, basically covers most of the navigation view and when tapped, returns the user back to the active call screen.
I'm experimenting with different ideas in SwiftUI, but haven't hit on any solid ideas yet and wanted to see if the community had any ideas for accomplishing this.
Here's a sample of what the UIKit code:
class MainNavController: UINavigationController {
func showActiveCallBar() {
...
let activeCallBarView = ...
...
view.addSubview(activeCallBarView)
}
}
Here's a gif of what happens when we switch back and forth, sorry, couldn't show the whole app. You can see the whole upper portion of the Navigation View gets covered.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在Swiftui中,我们将使用
@State
变量完成这样的事情,这将跟踪我们要显示活动的呼叫栏。当您的状态变量更改时,您的SwiftUI视图将被更新,并且将显示或隐藏活动的呼叫栏。看起来像这样。
state 具有更多有用的信息,Swiftui文档通常是很有帮助的,在这方面。您可以从Swiftui教程开始 https://develiper.apple.com/tutorials/tutorials/swiftui
In SwiftUI, we would accomplish something like this with an
@State
variable, which would track wether we want to show the active call bar.When your state variable changes, your SwiftUI view will be updated and the active call bar will be shown or hidden. It might look something like this.
The SwiftUI documentation of State has more helpful information, and the SwiftUI docs generally are quite helpful in this regard. You could start with the SwiftUI tutorials https://developer.apple.com/tutorials/swiftui