uitabbarcontrollerを使用して永続的なuiviewを追加します
-
26-10-2019 - |
質問
uitabbarcontrollerを使用しているアプリがあり、タブバーコントロールの後ろからスライドする必要がある別のビューがありますが、タブバーのコンテンツの前にあります。それが明確でない場合は、タブバーボタンを除くすべての前に表示されるタブ付きアプリに広がる広告を想像してください。
これまでのところ、私はこのようなものに見えるコードを持っていますが、これを行うためのより良い方法があれば、それを変更する気があります...
tabBarController.viewControllers = [NSArray arrayWithObjects:locationNavController, emergencyNavController, finderNavController, newsNavController, nil];
aboutView = [[AboutView alloc] initWithFrame:CGRectMake(0, window.frame.size.height - tabBarController.tabBar.frame.size.height - 37 ,
320, window.frame.size.height - tabBarController.tabBar.frame.size.height)];
[window addSubview:tabBarController.view]; // adds the tab bar's view property to the window
[window addSubview:aboutView]; // this is the view that slides in
[window makeKeyAndVisible];
現在、AboutViewはUiViewのサブクラスであり、下部の開始位置に座っていますが、TabbarControllerを隠しています。これを変更してタブを上に置くにはどうすればよいですか?
解決
現在のアクティブなビューコントローラーのビューのサブビューとして、AboutViewを追加する必要があります。 uitablebarcontroller. 。そのビューを介してアクセスできます SelectedViewController 財産。
AboutView実装にコードを追加して、表示されたときにビューをアニメーション化できます。
私は、タブバーコントロールの下に表示したいポップアップビューでこのようなことをします。にコードを追加できます DidMovetosuperview AboutView実装に関するメッセージ:
- (void)didMoveToSuperview
{
CGRect currentFrame = self.frame;
// animate the frame ... this just moves the view up a 10 pixels. You will want to
// slide the view all the way to the top
CGRect targetFrame = CGRectOffset(currentFrame, 0, -10);
// start the animation block and set the offset
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5]; // animation duration in seconds
[UIView setAnimationDelegate:self];
self.frame = targetFrame;
[UIView commitAnimations];
}
したがって、AboutViewが選択したビューコントローラーのビューに追加されると、自動的にアニメーション化されます。
所属していません StackOverflow