0

在我的应用程序中,纵向视图标签栏显示,横向视图设置为隐藏,这在 ios6 中运行顺利,但对于 iOS7,横向视图标签栏是隐藏的,但它的空间保持不变。按照我的代码。

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(![UICommonUtils isiPad]){

            if(toInterfaceOrientation == UIDeviceOrientationLandscapeRight || toInterfaceOrientation == UIDeviceOrientationLandscapeLeft) {

                [UICommonUtils hideTabBar:self.tabBarController];

            } else if(toInterfaceOrientation == UIDeviceOrientationPortrait || toInterfaceOrientation == UIDeviceOrientationPortraitUpsideDown){

                [UICommonUtils showTabBar:self.tabBarController];
            }
      }
}

隐藏标签栏

+(void)hideTabBar:(UITabBarController *)tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];

    float fHeight = screenRect.size.height;
    if(  UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width;
    }

    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
            view.backgroundColor = [UIColor blackColor];
        }
    }
}

显示标签栏

+(void)showTabBar:(UITabBarController *) tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float fHeight = screenRect.size.height - 49.0;

    if(  UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width - 49.0;
    }
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
        }
    }
}
4

1 回答 1

0

在方法中添加以下代码行viewDidLoad

if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) 
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
于 2014-02-18T15:04:03.810 回答