【问题标题】:Overlay tabbar with a view用视图覆盖标签栏
【发布时间】:2012-09-04 10:40:23
【问题描述】:
我在标签栏内有一个UIViewController。对于选项卡栏中的一个 VC,我允许界面在设备旋转时旋转。挑战在于,我想隐藏 Tab 栏并调整内部视图的大小。
我做了什么:
1) 在我的标签栏控制器中调用 - (void)willAnimateRotation.... 并将 self.tabBar.isHidden 设置为 true -> 标签栏消失了。
2) 调用- (void)willAnimateRotation.... 并将self.mapView.frame 设置为最大高度。
但是...我仍然在屏幕底部有一条黑色条纹,与标签栏的大小完全相同。有没有办法让标签栏完全消失?
【问题讨论】:
标签:
iphone
ios
uiviewcontroller
uitabbarcontroller
device-orientation
【解决方案1】:
[self hideTabBar:self.tabBarController];
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar 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)];
}
}
[UIView commitAnimations];
}
【解决方案2】:
这对我有用
- (void)viewDidLoad {
[super viewDidLoad];
previousRect = self.view.frame;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
{
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self.navigationController setNavigationBarHidden:TRUE animated:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:TRUE animated:FALSE];
}
else
{
[self.navigationController setNavigationBarHidden:FALSE animated:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:FALSE animated:FALSE];
}
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
UIInterfaceOrientation toOrientation = self.interfaceOrientation;
if ( self.tabBarController.view.subviews.count >= 2 )
{
UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0];
UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];
if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) {
transView.frame = CGRectMake(0, 0, 480, 320 );
tabBar.hidden = TRUE;
}
else
{
transView.frame = previousRect;
tabBar.hidden = FALSE;
}
}
}
【解决方案3】:
如果您希望在推送特定的UIViewController 时始终隐藏标签栏,您可以这样做:
self.hidesBottomBarWhenPushed = YES;