I'm using tabBarController and navigationController I'm displaying a Half ModalView as child over one of the viewControllers of the TabBarController. Note I'm using iPhone-5 simulator. My problem is that the topViewController height is 504 even though it should be 568 I can't determine the right position to display it just above the 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];
}];
First of all I would recommend to avoid things like this
CGRectMake(0, screenHeight/2, 320, 284);
(constants for settings sizes/positions of elements), you must calculate it from UIScreen object.
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width
And second: if you want to display top most view you can try to add it to UIWindow