iPhone 所有视图上的持久按钮

发布于 2024-09-11 03:35:05 字数 212 浏览 2 评论 0原文

我有一个导航应用程序,有许多用户导航到的屏幕。少数视图动态管理这些屏幕。我想要尝试做的是添加一个按钮,该按钮将始终显示在用户查看的每个屏幕上。我需要这样做,以便用户始终能够执行与按钮关联的操作,无论他们位于应用程序中的哪个位置。

是否可以通过仅添加此按钮一次并使其像我的导航栏一样在视图之间传递来实现此目的?或者我是否只需要手动添加此按钮及其功能到我拥有的每个视图文件中?

谢谢

I have a navigation app that has many screens the user navigates to. A handful of views manages these screens dynamically. What I want to try to do is add a button that will always show up on every screen the user views. I need to do this so that the user is always able to preform the action associated with the button regardless of where they are in the app.

Is it possible to achieve this by adding this button only once and having it passed between views like my navigation bar is? Or do I just have to man up and add this button and its functionality to every single view file I have?

Thanks

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

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

发布评论

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

评论(2

烟织青萝梦 2024-09-18 03:35:05

我想说这可能取决于按钮的作用。如果该按钮对所有视图都是通用的,这意味着它以相同的方式影响所有视图,因此不需要对给定视图进行自定义,那么执行此操作的方法是将函数包含在 App Delegate 中或作为您的子类导航控制器。

然后,您可以使用 rightBarButtonItem 始终显示相同的按钮并仅访问该方法。您只需在每个 viewDidLoad 中添加 rightBarButtonItem 代码(但它们都是相同的)。

我在一个项目上使用“升级”按钮做了类似的事情。由于该按钮所做的只是将 AppStore 启动到付费版本,因此它独立于所有视图,我可以将其放置在任何地方。

I would say it probably depends on what the button does. If the button is generic to all views, meaning it affects all views the same exact way so no customization for a given view is needed, then a way to do this would be to include the function in the App Delegate or as a subclass to your Navigation controller.

You can then use the rightBarButtonItem to always show the same button and just access that method. You would just have to add code for the rightBarButtonItem in each viewDidLoad (but they'd all be the same).

I did something similar to this with an "Upgrade" button on one project. Since all the button does is launch the AppStore to the paid version, it's independent of all views and I can place it anywhere.

撧情箌佬 2024-09-18 03:35:05

如果需要,您可以将该按钮放在导航栏上。或者,更通用的方法是将单个视图拆分为两个视图。一个很小,仅包含您的按钮,但始终保留在屏幕上。第二个是您的工作区,您可以换入和换出显示当前内容的视图。您会注意到,这就是导航控件和选项卡栏控件的工作方式。
最后一种方法是将不同的按钮放在每个视图上的同一位置,并让它们全部触发相同的操作。就用户而言,这看起来就像是同一个按钮。这里的缺点是您无法以简单的方式更改所有视图中的按钮。

You can put the button on the navigation bar if you want. Alternately, the more generic way to do this would be to split your single view into two views. One is small and only contains your button but always stays on the screen. The second is your workspace and you swap in and out the views that are displaying the current content. You'll note that this is the way the navigation controls and tab-bar controls work.
The last way to do this would be to put different buttons, in the same place, on each view and have them all trigger the same action. As far as the user is concerned this looks like the same button. Disadvantage here is that you can't alter the button across all views in a simple manner.

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