【问题标题】:UICollectionView frame changes after hide Nav Bar and Tab Bar隐藏导航栏和标签栏后 UICollectionView 框架发生变化
【发布时间】:2014-04-17 10:50:24
【问题描述】:

我试图保留我用作照片库的Collection Viewframe。但是在视图中隐藏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];
}

这是我的问题的图片:

非常感谢您的帮助

【问题讨论】:

    标签: ios uinavigationcontroller uitabbarcontroller uicollectionview


    【解决方案1】:

    我假设您正在使用 ScrollView 来展示照片。我在您的视图控制器中遇到了类似的问题并进行了设置 self.automaticallyAdjustsScrollViewInsets = NO; 应该有帮助。

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

    【讨论】:

    • 当使用self.tabBarController.tabBar.hidden = YES;隐藏标签栏时,此解决方案也有效。
    猜你喜欢
    • 1970-01-01
    • 2011-04-15
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 2017-03-14
    相关资源
    最近更新 更多