ios - 隐藏导航栏和标签栏后 UICollectionView 框架发生变化

标签 ios uinavigationcontroller uitabbarcontroller uicollectionview

我试图保留用作照片库的 Collection Viewframe。但是在 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

非常感谢您的帮助

最佳答案

我假设您正在使用 ScrollView 来展示照片。我在你的 View Controller 中遇到了类似的问题和设置 self.automaticallyAdjustsScrollViewInsets = NO; 应该有帮助。

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...

关于ios - 隐藏导航栏和标签栏后 UICollectionView 框架发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23131147/

相关文章:

ios - 使用正则表达式检查 Double 值是否具有某种格式

ios - 使用我的 swift 4 应用程序将 json 数组保存在 firebase 中

ios - iOS 设备可以使用 http 直播将音频/视频发送回服务器吗?

ios - 是否可以在 Swift 中为协议(protocol)实例设置观察者(KVO)

ios - 在 UINavigationController 堆栈 (IOS7) 的 UIWebview 中播放嵌入式视频的问题

javascript - iPad、iPhone 模态对话框滚动问题

ios - UITabBarController 中的 UINavigationController 视觉问题

ios - 移动索引 - 基于计时器

ios - 如何从选项卡栏 Controller 弹出或模态呈现 View Controller ?

iphone - 在 ViewController 中重新加载/刷新选项卡栏项目?