4
我正在嘗試保留作爲照片庫使用的Collection View
的frame
。但在隱藏在視圖UITabBarController
和UINavigationController
之後,其幀發生變化。隱藏導航欄和標籤欄後UICollectionView框架發生變化
這就是代碼我使用隱藏兩種:與我的問題
- (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];
}
這裏一個形象:
非常感謝您對您的幫助
此解決方案在使用'self.tabBarController.tabBar.hidden = YES;'隱藏標籤欄時也可以工作。 –