4

我正在嘗試保留作爲照片庫使用的Collection Viewframe。但在隱藏在視圖UITabBarControllerUINavigationController之後,其幀發生變化。隱藏導航欄和標籤欄後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]; 
} 

這裏一個形象:

enter image description here

非常感謝您對您的幫助

回答

8

我假設您正在使用ScrollView呈現照片。我有一個類似的問題,並設置您的視圖控制器 self.automaticallyAdjustsScrollViewInsets = NO; 應該幫助。

缺省值是YES,這允許視圖控制器響應於由所述 狀態欄,導航欄所消耗的屏幕區域調整 其滾動視圖的插圖,和工具欄或標籤欄。如果您想要自己管理滾動視圖插入調整,請將其設置爲NO ...

+2

此解決方案在使用'self.tabBarController.tabBar.hidden = YES;'隱藏標籤欄時也可以工作。 –