ios - 如何在 tabBarController 上方显示半个 modalView?

标签 ios navigationcontroller tabbarcontroller

我正在使用 tabBarController 和 navigationController 我在 TabBarController 的其中一个 viewController 上显示一个 Half ModalView 作为 subview 。 注意我使用的是 iPhone-5 模拟器。我的问题是 topViewController 的高度是 504,尽管它应该是 568 我无法确定将它显示在 tabBar 上方的正确位置。

UIViewController *viewCon =  [(UINavigationController*)[tabBarController selectedViewController] topViewController];

     UIViewController*vc=[tabBarController.viewControllers objectAtIndex:0];
        NSLog(@"vc,%f",vc.view.frame.size.height);// prints 568

        if (viewCon.childViewControllers.count == 0) {

        UIStoryboard* story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        _modal = [story instantiateViewControllerWithIdentifier:@"HalfModal"];
        [viewCon addChildViewController:_modal];

        _modal.view.frame = CGRectMake(0, screenHeight ,screenWidth, screenHeight);

        NSLog(@"TopviewController height ,%f",CGRectGetHeight(viewCon.view.frame));//prints 504

        frame = CGRectMake(0, 0, screenWidth, screenHeight);
        _view2 = [[UIView alloc]initWithFrame:frame];

        [viewCon.view addSubview:_view2];
        [viewCon.view addSubview:_modal.view];

        [UIView animateWithDuration:0.5
                         animations:^{
                             [_view2 setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.5]];                             

                             _modal.view.frame = CGRectMake(0, screenHeight/2, 320, 284);

                         }
                         completion:^(BOOL finished) {
                             [_modal didMoveToParentViewController:viewCon];
                         }];

最佳答案

首先我会建议避免这样的事情

CGRectMake(0, screenHeight/2, 320, 284);

(用于设置元素大小/位置的常量),您必须从 UIScreen 对象计算它。

CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width

其次:如果你想显示最顶层的 View ,你可以尝试将它添加到 UIWindow

关于ios - 如何在 tabBarController 上方显示半个 modalView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29228629/

相关文章:

ios - [[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault复用标识符:CellIdentifier]]的预期标识符

ios - 如何从我的 iOS View 访问导航 Controller 导航栏大小?

ios - 如何将主视图 Controller 添加到不是选项卡栏项目之一的选项卡栏 Controller ?

swift - 返回初始 View Controller 时选项卡栏消失

objective-c - 在 UITextView 中移动光标

ios - 将 SpriteKit 粒子添加到现有应用程序

ios - UITableView cellForRowAtIndexPath 中的 EXEC_BAD_ACCESS

ios - 在 iOS 上进行 segue 时将元素保留在导航 Controller 中

ios - 在另一个 View Controller 中调用方法,但不继续调用它?