自定义标签栏搞乱了 ScrollView
在我的 iPhone 应用程序中,我实现了一个自定义选项卡栏,它功能完美,没有任何问题。但是,我遇到了一个问题:基本上我的自定义选项卡栏实际上并不控制选项卡栏视图,它只是向底层标准 UITabBarController
发出信号,表明它应该 setSelectedIndex:1
等。它基本上只是一个可视化的自定义选项卡栏,背后没有任何逻辑。因此,我需要隐藏在幕后完成所有肮脏工作的底层标准 UITabBar
。
我和我的朋友 Google 遇到的最常见的事情是人们使用此代码来隐藏选项卡栏:
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[AppTabBarController_iPhone class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
确实,这确实将选项卡栏推到了视线之外,但它在任何滚动视图中带来了另一个问题:每个滚动视图的背景图像都会重复 44 像素(即已向下移动的选项卡栏的高度),因此这会带来真正难看的体验。
我可以采取某种 setFrame
hack 来解决此问题吗?或者您是否有更好的方法来隐藏选项卡栏以消除此问题?
In my iPhone app I have implemented a custom tab bar which functions perfectly, no problems there. However, there is one problem that I'm encountering: Basically my custom tab bar doesn't actually control the tab bar views, it just signals the underlying standard UITabBarController
that it should setSelectedIndex:1
, etc. It's basically only a visual custom tab bar without any logic behind it. Therefore, I need to hide the underlying standard UITabBar
that does all of the dirty work behind the scenes.
The most common thing I've come across with my friend Google is that people have used this code to hide the tab bar:
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[AppTabBarController_iPhone class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
Indeed, this does push the tab bar just out of sight, but it brings along another problem in any scroll views: The background image of every scrollview is getting repeated for 44 pixels (i.e. the height of the tab bar that has been shifted down) and so that makes for a truly ugly experience.
Is there some sort of setFrame
hack I can do to make this work out, or do you have a completely better way of hiding the tab bar that would eradicate this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是一个想法,与其隐藏原始的 UITabBar,为什么不直接用自定义的 UITabBar 覆盖它呢?除非他们的身高不同,否则应该没问题。
要覆盖它,您必须将自定义选项卡栏作为子视图添加到主窗口。
Just a thought, instead of hiding the original UITabBar why don't you just cover it with your custom UITabBar? Unless they have different heights you should be just fine.
To cover it you would have to add your custom tabbar as a subview to the main window.