Changing the UICollectionView wireframe after hiding the navigation bar and tab bar

I am trying to save frame Collection Viewwhich I use as a photo album. But after hiding in the view UITabBarController, UINavigationControllerits frame changes.

What I use code to hide 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 is the image with my problem:

enter image description here

Many thanks for your help.

+4
source share
1 answer

I assume that you are using ScrollView to present photos. I had a simillar problem and installing in your view controller self.automaticallyAdjustsScrollViewInsets = NO; should help.

- YES, , , . , ...

+8

Source: https://habr.com/ru/post/1536934/


All Articles