iOS 5 跨多个场景保持一致的标签栏

发布于 2024-12-19 06:55:16 字数 167 浏览 1 评论 0原文

我正在 iOS 5 上开发我的第一个 Apple 产品。当我不使用 UITabBarController 时,在多个场景中保持一致的 UITabBar 对象的最佳方法是什么?它只是一个标准的 UIViewController。我让标签栏在一个场景中按照我想要的方式工作,并且我希望能够将其复制到其他 4 个左右的场景中。

I am developing my first Apple product on iOS 5. What is the best way to maintain a consistent UITabBar object across multiple scenes when I'm not using the UITabBarController? It's just a standard UIViewController. I have the tab bar working just as I want it on one scene and I want to be able to duplicate it to my other 4-ish scenes.

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

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

发布评论

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

评论(6

靖瑶 2024-12-26 06:55:16

使用 UIAppearance API 用于在所有 UITabBar 实例上设置视觉属性。

id appearance = [UITabBar appearance];
[appearance setBackgroundImage:someImage];
[appearance setTintColor:someTintColor];
//...

这里是可以在 UITabBarUIAppearance 上设置的属性列表 代理人:

Use the UIAppearance API to set your visual properties on all UITabBar instances.

id appearance = [UITabBar appearance];
[appearance setBackgroundImage:someImage];
[appearance setTintColor:someTintColor];
//...

Here's a list of the properties that can be set on UITabBar's UIAppearance proxy:

顾忌 2024-12-26 06:55:16

我认为这个创新的答案会对您有用
物理按钮

I think this innovative Answer will use for you
Physical Button

此刻的回忆 2024-12-26 06:55:16

假设您确实不想使用 UITabViewController,那么让您的应用程序委托维护对全局 UITabBar 对象的引用,并且当您从一个视图切换到另一个视图时,您可以只需请求该实例并将其添加到视图层次结构中即可。

Assuming you really don't want to use a UITabViewController, then have your application delegate maintain a reference to your global UITabBar object and as you switch from view to view, you can just request that instance and add it the view hierarchy.

知你几分 2024-12-26 06:55:16

这非常简单且容易做到(我已经在多个应用程序中完成了)。

  1. 创建基于视图的应用程序。我们将这样创建的单个 VC 称为“MainViewController”。
  2. 使用图像、按钮以及 MainViewController.xib 中的内容创建顶栏。将顶层 UIView 的背景颜色设置为“Clear Color”。
  3. 在此 xib 中不添加任何其他内容。
  4. 为您需要的所有视图创建视图控制器和 Xib
    显示(包括初始/第一个视图)。我们称它们为 MyViewController1 &我的视图控制器2。
  5. 让 MainViewController 与 MyViewController1 具有“has a”关系。含义 MainViewController 将具有 MyViewController1 类型的成员变量/属性。
  6. MyViewController2 也是如此。
  7. 实例化 MyViewController1 & 2 在MainViewController的“viewDidLoad”方法中。
  8. 将它们添加为 MainViewController 的子视图。
  9. 对于初始视图(可能是 MyViewController1),将隐藏属性添加为 NO,对于另一个视图,将隐藏属性添加为 YES。
  10. 此时,您将看到 MainViewController 的顶栏和其下方的 MyViewController1 视图。
  11. 当需要切换到MyViewController2时,只需将其隐藏属性设置为NO,将MyViewController1的隐藏属性设置为YES即可。
  12. 如果您想设置从 MyViewController1 到
    MyViewController2,添加 CABasicAnimation/CATransition 到
    CALayers 到 MyViewController1 & MyViewController2(而不是
    主视图控制器)。然后你的顶栏(画在
    MainViewController)将保持坚如磐石的稳定,并且
    MyViewController1 & 2 将在其下切换/动画。
  13. 但是,如果您希望顶部栏消失并让新的顶部栏与下一个视图一起显示,只需将 CATransition/CAAnimation 等附加到 MainViewController 的 CALayer 即可。

如有任何问题,请随时提出。

It's very simple and easy to do (I've done it in multiple apps).

  1. Create a view based application. Let's call the single VC thus created as "MainViewController".
  2. Create your top-bar with images, buttons and what have you in MainViewController.xib. Set the background color of the top level UIView as "Clear Color".
  3. Add nothing else to this xib.
  4. Create View Controllers and Xibs for the all the views that you need
    to show (including the initial/first view). Let's call them MyViewController1 & MyViewController2.
  5. Let MainViewController have "has a" relationship with MyViewController1. Meaning MainViewController will have a member variable/property of the type MyViewController1.
  6. Ditto for MyViewController2.
  7. Instantiate MyViewController1 & 2 in "viewDidLoad" method of MainViewController.
  8. Add them as subviews of MainViewController.
  9. Add the hidden property to NO for the initial view (MyViewController1 maybe) and YES for the other one.
  10. At this point, you'll see the top-bar of the MainViewController and the MyViewController1's view under it.
  11. When you need to switch to MyViewController2, just set set its hidden property to NO, and MyViewController1's hidden property to YES.
  12. If you'd like to animate the transition from MyViewController1 to
    MyViewController2, add the CABasicAnimation/CATransition to
    CALayers to MyViewController1 & MyViewController2 (and not the
    MainViewController). Then your top-bar (drawn on
    MainViewController) will remain rock-solid stable and the
    MyViewController1 & 2 will switch/animate under it.
  13. If however, you'd like the top-bar to go away and the new top-bar to show up along with the next view, just attach CATransition/CAAnimation etc. to the CALayer of MainViewController.

Feel free to ask any questions.

醉殇 2024-12-26 06:55:16

您可以做的是使用视图来包装您想要动态的内容。然后您可以将第一个可见视图添加为该视图的子视图。接下来,您需要为视图(当前视图和要更改为的视图)之间的过渡设置动画,以模拟更改视图控制器。这是我使用的代码,它在两个视图之间执行此操作。我的“包装”视图称为内容视图。您需要将其与您设置的选项卡栏集成...

[ contentView addSubview:view2 ];
[ view1 removeFromSuperview ];

CATransition *animation = [ CATransition animation ];

[ animation setType:kCATransitionPush ];
[ animation setSubtype:kCATransitionFromRight ];
[ animation setDuration:0.5 ];
[ animation 
 setTimingFunction:[ CAMediaTimingFunction
                    functionWithName:kCAMediaTimingFunctionEaseInEaseOut
  ]
 ];

[[ contentView layer ]
 addAnimation:animation
 forKey:@"currentTransition"
 ];

尝试一下!

What you could do is use a view to wrap the content you want to be dynamic. Then you could add the first visible view as a subview of this view. Next you would need to animate a transition between the views ( the current view, and the one you want to change to ) to simulate changing a view controller. Here is code that I have used that does this between two views. My "wrapper" view is called content view. You would need to integrate this with what tab bar you have setup...

[ contentView addSubview:view2 ];
[ view1 removeFromSuperview ];

CATransition *animation = [ CATransition animation ];

[ animation setType:kCATransitionPush ];
[ animation setSubtype:kCATransitionFromRight ];
[ animation setDuration:0.5 ];
[ animation 
 setTimingFunction:[ CAMediaTimingFunction
                    functionWithName:kCAMediaTimingFunctionEaseInEaseOut
  ]
 ];

[[ contentView layer ]
 addAnimation:animation
 forKey:@"currentTransition"
 ];

Try it out!

冰葑 2024-12-26 06:55:16

这不是标准方法,但如果您确实想在应用程序中提供 tabBar 功能而不使用 tabBar。

在每个视图的底部创建 4-5 个自定义按钮(带图像)(大小 199 X 49 ),以便它完全占用视图的底部(如 tabBar)。在一个视图休息中仅给出一个按钮操作全部都被禁用了。此外,您提供的按钮功能应该更改图像以显示当前选项卡被单击。

This is not the Standard way but if you really want to give tabBar functionality in your application without using the tabBar.

Create a 4-5 custom buttons(with images) at the bottom of every view (size 199 X 49 ) so that it entirely consume the bottom of the view (like tabBar).Give only one of the buttons action in a one view rest all are disabled. Also the button function you give should change the image to show that the current tab is clicked.

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