Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView frame changes after hide Nav Bar and Tab Bar

I'm trying to keep the frame of a Collection View that I use as Photo Gallery. But after hide in the view the UITabBarController and the UINavigationController, its frame changes.

That's the code I use for hiding both:

- (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];
}

Here a image with my problem:

enter image description here

Thank you very much for your helping

like image 773
santibernaldo Avatar asked Feb 14 '23 04:02

santibernaldo


1 Answers

I assume You are using ScrollView to present photos. I've had a simillar problem and setting in your view controller self.automaticallyAdjustsScrollViewInsets = NO; should help.

Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself...

like image 117
kedzia Avatar answered Mar 05 '23 16:03

kedzia