shu*_*mey 6 iphone objective-c uitabbarcontroller uiview depth
我有一个使用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];
Run Code Online (Sandbox Code Playgroud)
目前aboutView是UIView的子类,位于底部的起始位置,但它隐藏了tabBarController.如何更改此选项以使选项卡位于顶部,但仍然在其他内容前面显示aboutView?
您需要将 aboutView 添加为UITableBarController中当前活动视图控制器中视图的子视图。您可以通过selectedViewController属性访问该视图。
您可以将代码添加到 aboutView 实现中,以便在视图出现时为其设置动画。
我在弹出视图中执行类似的操作,我希望该视图出现在选项卡栏控件下。您可以在 aboutView 实现的didMoveToSuperview消息中添加一些代码:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
因此,当您的 aboutView 添加到所选视图控制器的视图时,它会自动动画化。