包含导航栏和标签栏的视图向下移动了大约4毫米

时间:2012-07-09 04:52:11

标签: iphone ios xcode uinavigationcontroller uitabbarcontroller

在我的应用程序中,从登录界面我导航到一个班级说classA,就像这样

classA *objUserHome = [[classA alloc]init];
        [self presentModalViewController:objUserHome animated:YES];
        [objUserHome release];

和ClassA有一个导航栏和一个标签栏(其中有5个标签),我已经以编程方式创建了我的标签栏

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Create tab bar controller and navigation bar controller

    tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *arrControllers = [[NSMutableArray alloc] initWithCapacity:5];

    //Add PunchClock to tab View Controller
    PunchClock* objPunchClock = [[PunchClock alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objPunchClock];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objPunchClock release];

    //Add Time_Sheet to tab View Controller
    Time_Sheet* objTime_Sheet = [[Time_Sheet alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objTime_Sheet];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objTime_Sheet release];

    //Add PTO to tab View Controller
    PTO* objPTO = [[PTO alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objPTO];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objPTO release];

    //Add PunchClock to tab View Controller
    CrewPunch* objCrewPunch = [[CrewPunch alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objCrewPunch];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objCrewPunch release];

    //Add PunchClock to tab View Controller
    Reports* objReports = [[Reports alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objReports];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objReports release];

    // Add this view controller array into the tab bar

    //self .viewControllers = arrControllers;
     tabBarController .viewControllers = arrControllers;

    [arrControllers release];
    [self.view addSubview:[tabBarController view]];


}

ClassA is inherited from UIViewController

现在的问题是,在导航到classA之后,classA的视图向下移动了大约4mm like this为什么呢?我怎么能解决这个问题,请提前帮助我,而不是提前

4 个答案:

答案 0 :(得分:1)

在2个或更多视图之间使用故事板和Modal Transition时,您可能会遇到与上述类似的错误。

如果您使用Modal Transition中的ViewControllerAViewControllerZ,然后尝试Modal TransitionViewControllerZ返回ViewControllerA,有时会看到ViewControllerA {1}}稍微被推下窗口。

使用以下方法可以防止这种情况:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

ViewControllerZViewControllerAViewControllerZ上的活动返回{{1}}

答案 1 :(得分:0)

您可能在Interface Builder或XIB文件中选择了一些顶部栏,并另外设置了导航栏。不要选择XIB文件中的任何顶部栏。

答案 2 :(得分:0)

尝试以下

[self.navigationController.view addSubview:[tabBarController view]];

答案 3 :(得分:0)

经过长时间的研究后,我终于通过继承UINavigationController而非UIViewControler

的课程来解决此问题