2012-02-06 12 views
5

iOSプログラミングが初めてです。私は本当にあなたの助けが必要です。ビューコントローラから必要なときにタブバーを表示/非表示にする

私はマップ(google API)に私を連れて行くログイン画面があります。作成された注釈をクリックすると、2つのビューを持つタブバーをロードしたいと思う。

私は検索して、私は、タブレットを必要に応じて、appdelegateと表示/非表示にタブバーを追加する必要があることがわかった。

ので、私はLoad_tabBar方法とするとき、それはremove_tabBarメソッドを呼び出して、私をバッククリック呼び出すとき、それは仕事をした

-(void)Load_tabBar{ 
[self.navigationController.view removeFromSuperview]; 
[self.window addSubview:tabBarController.view]; 
[self.window makeKeyWindow];} 

-(void)remove_tabBar{ 
self.tabBarController.selectedIndex=0; 
[self.tabBarController.view removeFromSuperview]; 
[self.window addSubview:navigationController.view]; 
[self.window makeKeyWindow];} 

としてタブバーを表示し、非表示にする2つの機能を作りました。私は再びLoad_tabBarメソッドを呼び出して、バック、それがエラーを

を与えるクラッシュした場合 - [UILayoutContainerViewウィンドウ]:割り当て解除インスタンスに0x563b0b0

に送信されたメッセージは、編集された:PS:私はビューコントローラにタブバーのビューを追加し、それを押すことができます見る?

のthnx

答えて

8

使用私は、この2つの方法があなたを助けることを願って、このself.hidesBottomBarWhenPushed = YES;

+0

まだ同じで:( –

+0

iがビューコントローラにタブバーのビューを追加し、そのビューをプッシュすることができ、BT追加 –

+0

あなたがいるとき?あなたのコードを使用する必要はありません – Tendulkar

1

- (void) hideTabBar:(UITabBarController *) tabbarcontroller { 

int height = 480; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3]; 

for(UIView *view in tabbarcontroller.view.subviews) { 
    if([view isKindOfClass:[UITabBar class]]) { 
     [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)]; 
    } 
    else { 
     [view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)]; 
    } 
} 
[UIView commitAnimations]; 

}

- (void) showTabBar:(UITabBarController *) tabbarcontroller { 

int height = 480; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3]; 

for(UIView *view in tabbarcontroller.view.subviews) { 

    if([view isKindOfClass:[UITabBar class]]) { 
     [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];    
    } 
    else { 
     [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)]; 
    } 
}  

[UIView commitAnimations]; 

}

AppDelegateクラスにこの2つのメソッドを配置し、あなたの要件に応じて必要な場所に呼び出します。

+0

サブビューのフレームサイズを変更したくありません。サブビューも消えています –

+0

その後、ちょうどサイズが必要です!!!! –

+0

iPhoneとiPadの両方を扱うための調整を追加しました。そのようにウィンドウの幅と高さを取得する float height = self.window.frame.size.height; float width = self.window.frame.size.width; – Sheepdogsheep

1

この方法は間違いなく機能します。あなたはこのように、あなたがそれをプッシュする前の方法でそれを配置する必要があります。

-actionThatPushTheViewController { 

    //create the view controller here, do some init. 

    //then: 
    theViewControllerToBePushed.hidesBottomBarWhenPushed = YES; 

    //push it here like this: 
    [self.navigationController pushViewController:theViewControllerToBePushed animated:YES]; 
関連する問題