UIView frame issue

笑着哭i 提交于 2019-12-11 19:28:51

问题


I am having a weird problem. I have two view controllers. A homeViewController and a settingViewController.

homeViewController has no navigation bar while the settingViewController has.

Now the issue is when i push settingViewController and get back from it my homeViewController view's height gets small. (view's height - navigation bar height)

(don't want to adjust frame manually)

// homeViewController
-(void) settingButtonPressed {

    SettingsViewController *svc = [[SettingsViewController alloc] init];
    [self.navigationController pushViewController:svc animated:YES];
}

// settingViewController
-(void) viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    self.navigationItem.hidesBackButton = NO;
    [UIApplication sharedApplication].statusBarHidden = YES;

    UIInterfaceOrientation statusBarOrientation =[UIApplication sharedApplication].statusBarOrientation;

    [self willAnimateRotationToInterfaceOrientation:statusBarOrientation duration:0.0];
}

-(void) viewWillDisappear:(BOOL)animated {

    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = YES;
}

Please suggest the work around for it.


回答1:


Write in homeVC.m

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.navigationController.navigationBarHidden = YES;
}

And in settingVC.m

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:(BOOL)animated];   

    self.navigationController.navigationBarHidden = YES;
}



回答2:


Instead of trying to govern the visibility of the navigation bar in view will appear and will disappear for the individual view controllers, try governing it in the navigation controller's delegate.




回答3:


try to settingViewController 's pop action method

self.navigationController.navigationBarHidden = YES;


来源:https://stackoverflow.com/questions/18779128/uiview-frame-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!