隐藏导航栏和标签栏后 UICollectionView 框架发生变化
Posted
技术标签:
【中文标题】隐藏导航栏和标签栏后 UICollectionView 框架发生变化【英文标题】:UICollectionView frame changes after hide Nav Bar and Tab Bar 【发布时间】:2014-04-17 10:50:24 【问题描述】:我试图保留我用作照片库的Collection View
的frame
。但是在视图中隐藏UITabBarController
和UINavigationController
后,它的框架发生了变化。
这是我用来隐藏两者的代码:
- (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];
这是我的问题的图片:
非常感谢您的帮助
【问题讨论】:
【参考方案1】:我假设您正在使用 ScrollView 来展示照片。我在您的视图控制器中遇到了类似的问题并进行了设置
self.automaticallyAdjustsScrollViewInsets = NO;
应该有帮助。
默认值为YES,允许视图控制器调整 它的滚动视图插入以响应所消耗的屏幕区域 状态栏、导航栏和工具栏或标签栏。如果你设置为 NO 想要自己管理滚动视图插图调整...
【讨论】:
当使用self.tabBarController.tabBar.hidden = YES;
隐藏标签栏时,此解决方案也有效。以上是关于隐藏导航栏和标签栏后 UICollectionView 框架发生变化的主要内容,如果未能解决你的问题,请参考以下文章