如何仅在某些视图控制器上显示某个UI?

发布于 2025-02-05 23:34:01 字数 483 浏览 1 评论 0原文

我有一个希望在两个视图控制器上显示的UiprogressView,它目前正在使用带有4个视图控制器的UitabbarController,因此我可以从“导航”选项卡中导航到四个中的任何一个。问题是我希望此进度视图仅在4个视图控制器中的2个显示。

我当前的方法是在A和B上分别构建相同的进度视图在更新当前进度之前,它将达到0。

在Tab Bar控制器中,我需要

self.updateProgressView(prog)

在完成处理程序内部进行操作,因为我需要等待数据才能计算PROG。

在我的VC中

VC.updateProgressView = {prog in 
   progressBar.setProgress(prog)
}

I have a UIProgressView that I wish to display on two view controllers, A and B. I am currently using a UITabBarController with 4 view controllers, such that I can navigate to any of the four from the navigation tab. The issue is that I want this progress view to only be displayed on 2 of the 4 view controllers.

My current approach is to build the same progress view separately on A and B. But the issue is that when I navigate from A to B or vice verse, the progress view does not increase smoothly, but updates in a very 'jumpy' manner where it goes to 0 before updating to the current progress.

In the tab bar controller I do

self.updateProgressView(prog)

inside of a completion handler as I need to wait for data before I can compute prog.

In my VCs I do

VC.updateProgressView = {prog in 
   progressBar.setProgress(prog)
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2025-02-12 23:34:01

标签栏控制器管理单独的持久视图控制器。每个视图控制器都有自己的视图层次结构。当您切换选项卡时,Tab Bar Controller切换到显示该选项卡的视图控制器及其视图。

不能具有相同的进度视图出现在多个选项卡上。您需要为希望显示的每个选项卡设置单独的进度视图。

您可以做的是在每个选项卡的视图控制器上实现视图WillAppear方法,该方法将进度视图设置为当前进度值,以便在显示时,它已经具有所需的进度值。您将需要某种方法在视图控制器之间传达进度值。

A tab bar controller manages separate persistent view controllers. Each view controller has it’s own view hierarchy. When you switch tabs, the tab bar controller switches to displaying that tab’s view controller and it’s views.

You can’t have the same progress view appear on multiple tabs. You need to set up separate progress views for each tab where you want it to be shown.

What you can do is implement viewWillAppear methods on each tab’s view controller that sets the progress view to the current progress value, so that by the time it is shown, it already has the desired progress value. You will need some way to communicate the progress value between view controllers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文