在 iPhone SDK 3.1 中隐藏 UINavigation 屏幕中的 TabBar 会导致屏幕发生 20 像素偏移
绅士们, 我是 iPhone 和 iPhone 的新手。 Objective-C,有着悠久的过程语言背景。
我正在尝试模仿全食超市的食谱搜索功能。在该应用程序中,屏幕顶部有一个导航栏,底部有一个选项卡栏,屏幕顶部有一组三个按钮。选择一个按钮会出现一个从底部向上滑动的屏幕,覆盖 TabBar。上滑屏幕包含一个选择器和一个“完成”按钮。这不是模态屏幕,您可以从上面选择不同的按钮,并且选择器将动态更改,这一事实证明了这一点。另外,这不是行动表。
在重新创建此行为时,我使用 iPhone 的 ScrollViewSuite 示例中的 Autoscroll 项目来呈现非模态上滑屏幕。这很有效。我可以通过选择不同的按钮来动态更改上滑屏幕中的选择器。
由于我希望上滑屏幕覆盖 TabBar,因此我使用了 的建议http://osdir.com/ml/iPhoneSDKDevelopment/2009-01/msg00246.html。简而言之,增加 tabBarController.view.frame 高度可以有效地使框架大于屏幕,并且 TabBar(固定在底部)将从用户的视图中删除。上滑屏幕和隐藏 TabBar 的组合是可以接受的。生活相对美好。我所需要做的就是添加导航栏。
但是,当我将 IB 中的屏幕从视图控制器更改为导航控制器屏幕时,我在隐藏 TabBar 时以某种方式在视图中引入了 20 像素的偏移!? NavigationBar 本身很好,但其下方的所有其他内容都会向上移动 20 像素。 (不过,上滑屏幕仍然没问题。)(20 像素是 iPhone 状态栏的高度。)
我的 IB 是标准排列,有一个带有 TabBarCongroller 的 MainWindow.xib,以及其中的 NavigationController。
这是代码:
- (void)toggleThumbView
{
if (!thumbViewShowing)
{
[self createSlideUpViewIfNecessary]; // no-op if slideUpView has already been created
//Hide the TabBar, which introduces a 20 pixel shift up of everything except the navigation bar
UITabBar *ntoTabBar = self.tabBarController.tabBar;
CGRect tbcFrame = self.tabBarController.view.frame;
self.tabBarController.view.frame = CGRectMake(tbcFrame.origin.x ,
tbcFrame.origin.y ,
tbcFrame.size.width ,
tbcFrame.size.height + ntoTabBar.frame.size.height);
//The following code really doesn't matter for discussions about the problem, simply resizing the
//tabBarController.view.frame above has already introduced the 20 pixel problem
CGRect frame = [slideUpView frame];
frame.origin.y -= frame.size.height ;
frame.origin.y += ntoTabBar.frame.size.height ;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[slideUpView setFrame:frame];
[UIView commitAnimations];
thumbViewShowing = !thumbViewShowing;
}
}
我尝试使用 autoresizingMask 和 autoResizesSubviews。以下消除了 20 像素的偏移:
[self.tabBarController.view setAutoresizesSubviews:NO];
不幸的是,它也使 TabBar 不被隐藏。我认为 20 像素可能是线索,因此尝试在所有 XIB 上取消选中 IB“想要全屏”,但无济于事。我已经检查过&取消选中 NIB 的调整大小,并且我删除了所有模拟界面元素,以便程序应该能够控制调整大小(我相信这些模拟会禁止程序控制?)同样,似乎没有任何效果。将 tbcFrame.origin.y 增加 20 像素可以消除屏幕移位,但会导致导航栏降低 20 像素,覆盖下面的所有内容,并在顶部留下可爱的 20 像素边距。问题出现在3.0 SDK模拟器上,我升级到了3.1.2。很高兴拥有最新/最好的,但它并没有解决我的问题。
如果我还没有秃顶,我会把头发拔掉。任何关于去哪里寻找的建议将不胜感激。通过单独的 ViewController 推送上滑视图并消除 TabBar 的编程隐藏会更好吗?比如:
DetailViewController *dvc = [[DetailViewController alloc] init];
dvc.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:dvc animated:YES];
[dvc release];
提前谢谢你,
Bob B.
Gentlepeople,
I'm a newbie to iPhone & Objective-C, coming from a long background of procedural language.
I'm attempting to emulate the functionality of the Whole Foods' recipe search. In that app, the screen has a NavigationBar at the top, a TabBar at the bottom, and a grouping of three buttons toward the top of the screen. Selecting a button presents a slide-up screen from the bottom, covering the TabBar. The slide-up screen contains a picker, and a 'Done' button. This is not a modal screen, as witnessed by the fact that you can select a different button from above, and the picker will dynamically change. Also, this isn't an Action Sheet.
In recreating this behavior, I used the Autoscroll project from the iPhone's ScrollViewSuite sample to present a non-modal slide-up screen. This worked well. I can dynamically change the picker in the slide-up screen by selecting different buttons.
Since I wanted the slide-up screen to cover the TabBar, I used a suggestion from http://osdir.com/ml/iPhoneSDKDevelopment/2009-01/msg00246.html. In short, increasing the tabBarController.view.frame height effectively makes the frame larger than the screen, and the TabBar (which is anchored to the bottom) is removed from the user's view. The combination of the slide-up screen and hiding the TabBar was acceptable. Life was relatively rosy. All I needed to do was add the NavigationBar.
But when I changed the screen in IB from a View Controller to make it a Navigaion Controller screen, I somehow introduced a 20 pixel shift in the view when hiding the TabBar!? The NavigationBar itself is fine, but everything else underneath it shifts up by 20 pixels. (The slide-up screen is still fine, however.) (20 pixels is the height of the iPhone's status bar.)
My IB is the standard arrangement, having a MainWindow.xib with the TabBarCongroller, and the NavigationControllers within that.
Here is the code:
- (void)toggleThumbView
{
if (!thumbViewShowing)
{
[self createSlideUpViewIfNecessary]; // no-op if slideUpView has already been created
//Hide the TabBar, which introduces a 20 pixel shift up of everything except the navigation bar
UITabBar *ntoTabBar = self.tabBarController.tabBar;
CGRect tbcFrame = self.tabBarController.view.frame;
self.tabBarController.view.frame = CGRectMake(tbcFrame.origin.x ,
tbcFrame.origin.y ,
tbcFrame.size.width ,
tbcFrame.size.height + ntoTabBar.frame.size.height);
//The following code really doesn't matter for discussions about the problem, simply resizing the
//tabBarController.view.frame above has already introduced the 20 pixel problem
CGRect frame = [slideUpView frame];
frame.origin.y -= frame.size.height ;
frame.origin.y += ntoTabBar.frame.size.height ;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[slideUpView setFrame:frame];
[UIView commitAnimations];
thumbViewShowing = !thumbViewShowing;
}
}
I've tried playing with the autoresizingMask and the autoResizesSubviews. The following eliminates the 20 pixel shift:
[self.tabBarController.view setAutoresizesSubviews:NO];
Unfortunately it also keeps the TabBar from being hidden. Thinking the 20 pixels might be the clue, I've experimented with unchecking the IB 'Wants Full Screen' on all of the XIB's, but to no avail. I've checked & unchecked the resize from NIB, and I've removed all of the Simulated Interface Elements so that the program should have control of the resizing (I believe having those simulated prohibits the program control?) Again, nothing seems to be doing the trick. Increasing the tbcFrame.origin.y by 20 pixels eliminates the screen shift, but causes the NavigationBar to be lowered by 20 pixels, covering anything below and leaving a lovely 20 pixel margin at the top. The problem appeared in the 3.0 SDK simulator, and I upgraded to the 3.1.2. Nice to have the latest/greatest, but it didn't solve my problem.
I'd pull my hair out if I wasn't already bald. Any suggestions on where to look would be greatly appreciated. Would it be better to push the slide-up view via a separate ViewController and eliminate the programatic hiding of the TabBar? Something like:
DetailViewController *dvc = [[DetailViewController alloc] init];
dvc.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:dvc animated:YES];
[dvc release];
Thank you in advance,
Bob B.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,如果我能理解的话,你的问题是你的“一种”模式视图被覆盖了你的导航栏距底部 20px,不是吗?
如果是,请尝试转到“一种”模式视图的 NIB 文件,并检查“状态栏”选项是否选择了“无”。如果是这样,请尝试更改为“灰色”,例如。
我希望它能解决这个问题,如果没有,请告诉我,我会尝试看看可能是什么。
干杯,
虚拟网络
So, if I could understand it, your problem is that your "a kind of" modal view is overridden you navigation bar 20px from the bottom, isn't it?
If yes, try to go to the NIB file of your "a kind of" modal view and check if the option "Status Bar" is with "none" selected. If it is like that, try to change to "Gray", for example.
I hope it will fix this issue, if not, let me know and I will try to see what it could be.
Cheers,
VFN