iOS 版本之间的 UIToolbar 混乱

发布于 2024-12-29 08:23:01 字数 1269 浏览 3 评论 0原文

所以...我的问题有点奇怪。我有一个简单的 UIToolbar 被添加到在 viewDidLoad 时调用的 navigationController 的视图层次结构中。听起来很简单,对吧?问题是:工具栏本身是透明的,但按钮不是低于 iOS 5 的任何版本。

我整夜尝试重新排列和重新排序 setFrame、setTranslucent 和 setStyle 的调用,但没有任何效果,它只是空白!

所以我脑子里冒出一个问题:如果我创建一个新项目,然后制作完全相同的 UIToolbar 会怎样?嗯,它成功了。完美。于是我又脑补了一下:如果只是我的实例坏了怎么办?所以我在现有项目中创建了一个新工具栏,它显示为空白...

这让我相信我的 navigationController 的视图层次结构已损坏,但以何种方式损坏,我不知道...有谁知道如何解决我的难题(这是模拟器的问题,还是 iOS 4.3.2 的问题?)?

代码(适用于 iOS 5+,(尽管已被弃用,但很搞笑),以及其他项目,但不是我的):

toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 22, self.view.bounds.size.width, 44)]autorelease]; 
    [toolbar setBarStyle:UIBarStyleBlackTranslucent];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; 
    [self.view addSubview:toolbar];   

以下是来自 iOS 4.3.2 模拟器(顶部)和 iOS 5.0.1 模拟器(底部)的图片: iOS 4.3.2 模拟器 iOS 5.0.1 Simulator

编辑:根据 Rob 的建议,我已将代码更改为 self.view addSubview...但是没有变化。至于他为什么不使用 navigationController 的内置工具栏的问题,这是因为我实际上有两个工具栏,它们通过图像中的操作按钮上下动画。

编辑 2:为了清楚起见,请观察屏幕截图。为什么它是看不见的!!!?我有动画和视图层次结构。如果有人需要查看 viewDidLoad 方法,它相当庞大且麻烦......

So... My question is a bit of an odd one. I have a simple UIToolbar being added to the view hierarchy of a navigationController called at viewDidLoad time. Sounds simple, right? Well here's the problem: the toolbar itself is transparent, but the buttons aren't in any version less than iOS 5.

I've tried all night to rearrange and reorder the calling of setFrame, setTranslucent, and setStyle, but nothing had worked, it's just blank!

So I had a brain fart: what if I made a new project, then made the exact same UIToolbar? Well, it worked. Perfectly. So I had another brain fart: what if it's just that my instance is broken? So I made a new toolbar in the existing project, and it showed up blank...

This leads me to believe that my navigationController's view hierarchy is corrupted, but in what way, I have no idea... Does anyone know how to solve my conundrum (Is this a simulator thing, or an iOS 4.3.2 thing?)?

CODE (works on iOS 5+, (hilariously despite deprecation), and in other projects, just not mine):

toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 22, self.view.bounds.size.width, 44)]autorelease]; 
    [toolbar setBarStyle:UIBarStyleBlackTranslucent];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; 
    [self.view addSubview:toolbar];   

Here are pictures from the iOS 4.3.2 simulator (top) and the iOS 5.0.1 simulator (bottom):
iOS 4.3.2 Simulator
iOS 5.0.1 Simulator

EDIT: As per Rob's suggestion, I have changed the code to self.view addSubview... yet there is no change. And as for his question as to why I do not utilize the navigationController's built in toolbar, it is because I actually have TWO toolbars that are animated up and down by that action button in the image.

EDIT 2: For clarity, observe the screenshots. WHY is it INVISIBLE!!!?? I have the animations and view hierarchy down. If anybody needs to see the viewDidLoad method, it's fairly massive and cumbersome...

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

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

发布评论

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

评论(3

海的爱人是光 2025-01-05 08:23:01

您不应该弄乱 UINavigationController 的视图树。您应该只弄乱您提供的视图树的部分。

如果您使用的是 UINavigationController,为什么不直接使用导航控制器为您提供的工具栏呢?

UINavigationController 类参考:显示工具栏
UINavigationController 类参考:配置自定义工具栏
UIViewController 类参考setToolbarItems:animated:

You should not mess with the UINavigationController's view tree. You should only mess with the part of the view tree that you provide.

If you're using a UINavigationController, why don't you just use the toolbar that the navigation controller provides for you?

UINavigationController Class Reference: Displaying a Toolbar
UINavigationController Class Reference: Configuring Custom Toolbars
UIViewController Class Reference: setToolbarItems:animated:

我早已燃尽 2025-01-05 08:23:01

既然它已经贬值了,为什么不试试这个 就像文档中所说的

[toolbar setBarStyle:UIBarStyleBlack];
[toolbar setTranslucent:YES];

Since it's depreciated, why don't you try this like it says in the docs?

[toolbar setBarStyle:UIBarStyleBlack];
[toolbar setTranslucent:YES];
情域 2025-01-05 08:23:01

您希望出现两个根据操作按钮上下滑动的工具栏。不过,您实际上并不需要两个工具栏...尝试将此作为过渡:

[ toolbar setToolbarHidden: YES animated: YES ] ;
toolbar.topViewController.toolbarItems = < whatever the new toolbar should look like > ;
[ toolbar setToolbarHidden: NO animated: YES ];

这里的想法是,根据文档,工具栏的外观将由当前视图控制器的toolbarItems 属性控制。您可以制作看起来非常像您想要的任何东西的自定义工具栏项目实例。

您可能需要将对 setToolbarHidden: 的两次调用分开,以便运行循环有机会在您将隐藏的工具栏恢复之前绘制它。

You want the appearance of two toolbars sliding up and down according to the action button. You don't really need two toolbars, though... try this as a transition:

[ toolbar setToolbarHidden: YES animated: YES ] ;
toolbar.topViewController.toolbarItems = < whatever the new toolbar should look like > ;
[ toolbar setToolbarHidden: NO animated: YES ];

The idea here is that the appearance of the toolbar would be controlled by the toolbarItems property of the current view controller, per the documentation. You can make custom tool bar item instances that look pretty much like anything you want.

You might need to separate the two calls to setToolbarHidden: so that the run loop has a chance to draw the hidden toolbar before you bring it back.

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