我使用的是TabBarController和navigationController,我在tabBarController的一个viewControllers上显示半个ModalView。注意,我使用的是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];
}];发布于 2015-03-24 09:16:28
首先,我建议避免出现这种情况。
CGRectMake(0, screenHeight/2, 320, 284);(元素的设置大小/位置的常量),必须从UIScreen对象中计算它。
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width第二:如果您想显示最上面的视图,可以尝试将其添加到UIWindow中。
https://stackoverflow.com/questions/29228629
复制相似问题