隐藏导航栏和选项卡栏后,UICollectionView框架会发生更改

时间:2014-04-17 10:50:24

标签: ios uinavigationcontroller uitabbarcontroller uicollectionview

我正在尝试保留我用作照片库的frame Collection View。但是在隐藏在UITabBarControllerUINavigationController的视图中后,其框架会发生变化。

这是我用来隐藏两者的代码

- (void)hideTabBar:(UITabBarController *) tabbarcontroller
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0];


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

    }
    else
    {
        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];
}

- (void)showTabBar:(UITabBarController *) tabbarcontroller
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0];

    if(IS_IPHONE_5)
    {
        for(UIView *view in tabbarcontroller.view.subviews)
        {
            if([view isKindOfClass:[UITabBar class]])
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 519, view.frame.size.width, view.frame.size.height)];

            }
            else
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 519)];
            }
        }

    }
    else
    {
        for(UIView *view in tabbarcontroller.view.subviews)
        {

            if([view isKindOfClass:[UITabBar class]])
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];

            }
            else
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
            }
        }

    }



    [UIView commitAnimations];
}

- (void)hideNavBar:(UINavigationController *) navBarController
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0];

    [self.navigationController setNavigationBarHidden:YES];

    [UIView commitAnimations];
}

- (void)showNavBar:(UINavigationController *) navBarController
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0];
   [self.navigationController setNavigationBarHidden:NO];

    [UIView commitAnimations];
}

这是我的问题的图片:

enter image description here

非常感谢您的帮助

1 个答案:

答案 0 :(得分:8)

我假设您使用ScrollView来呈现照片。我在视图控制器中遇到了类似问题和设置 self.automaticallyAdjustsScrollViewInsets = NO; 应该有所帮助。

  

默认值为YES,允许视图控制器进行调整   它的滚动视图会响应屏幕区域的内容   状态栏,导航栏以及工具栏或标签栏。如果你设置为NO   想要自己管理滚动视图插入调整...