xcode 包含导航栏和选项卡栏的视图向下移动约4mm

mzmfm0qo  于 2023-08-07  发布在  其他
关注(0)|答案(4)|浏览(59)

在我的应用程序中,我从登录屏幕导航到一个类,比如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,如下图所示。为什么会这样呢?我该如何解决此问题?


的数据

new9mtju

new9mtju1#

在两个或更多视图之间使用故事板和Modal Transition时,您可能会遇到类似于上面的错误。
如果您使用Modal TransitionViewControllerAViewControllerZ,然后尝试从ViewControllerZ返回到ViewControllerAModal Transition,有时ViewControllerA的视图会稍微向下推窗口。
这可以通过以下方法来防止:

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

字符串
ViewControllerZ上的事件返回到ViewControllerA

pnwntuvh

pnwntuvh2#

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

yqhsw0fo

yqhsw0fo3#

尝试如下

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

字符串

yfjy0ee7

yfjy0ee74#

经过长时间的研究,我终于解决了这个问题,只是从UINavigationController继承了这个类,而不是UIViewControler

相关问题