そのためのストーリーボードは必要ありません。そこにビューをドラッグして特定のクラスに割り当て、その中のすべてのものをプログラムすることはできますが、本当にビューが 1 つしか必要ない場合は、ストーリーボードは役に立ちません。何かを変更したい場合は、サブビューをプログラムで処理する必要があります。これは非常に優れており、次のような優れた機能がありますanimationWithDuration:
UITabBarController のどのタブが選択されているかを確認するには、選択さself.tabBarController.selectedIndex
れているタブの特定のインデックスを使用して比較できます。
編集:
タブにインデックス 0 の緑色のボタンがあり、同じボタンが少し上にスライドし、インデックス 1 のタブがタップされたときに緑色のボタンの場所に赤いボタンが表示されると仮定します。
UIButton *greenButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 320, 100, 20)];
greenButton.backgroundColor = [UIColor greenColor];
[self.view addSubview:greenButton];
UIButton *redButton = [[UIButton alloc] initWithFrame:CGRectMake(0, greenButton.frame.origin.y, 100, 20)];
greenButton.backgroundColor = [UIColor redColor];
if (self.tabBarController.selectedIndex == 1) {
[UIView animateWithDuration:1.0 animations:^{
greenButton.frame = CGRectMake(0, 300, 100, 20);
} completion:^(BOOL finished) {
[self.view addSubview:redButton];
}];
}
最初に 2 つのボタンを作成し、緑色のボタンをビューに追加します。(最初のビューはインデックス 0 にあります)。次に、selectedIndex が 1 であるかどうかを確認し、ボタンをアニメーション化します。