首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在modalView上方显示半个tabBarController?

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

Stack Overflow用户
提问于 2015-03-24 09:08:49
回答 1查看 165关注 0票数 0

我使用的是TabBarController和navigationController,我在tabBarController的一个viewControllers上显示半个ModalView。注意,我使用的是iPhone-5模拟器。我的问题是,topViewController的高度是504,即使应该是568,我也不能确定正确的位置来显示它刚好在tabBar之上。

代码语言:javascript
复制
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];
                         }];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-24 09:16:28

首先,我建议避免出现这种情况。

代码语言:javascript
复制
CGRectMake(0, screenHeight/2, 320, 284);

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

代码语言:javascript
复制
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width

第二:如果您想显示最上面的视图,可以尝试将其添加到UIWindow中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29228629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档