我花了一些時間處理同樣的問題。在iOS8的模態導航控制器上推視圖控制器導致視圖控制器的大小與根視圖控制器相同,而對於iOS7,第二個視圖控制器具有默認大小的模式表單(540.f,620.f) 。唯一的工作解決,我能想出到目前爲止,對於iOS7和iOS8上如下:
ViewController1.m
@interface ViewController1()
@end
@implementation ViewController1
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.view.superview.bounds = CGRectMake(0, 0, VC1_WIDTH, VC1_HEIGHT);
}
- (void)nextTapped:(id)sender {
ViewController2 *vc2 = [storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
[self.navigationController pushViewController:vc2 animated:NO];
// call after push
self.navigationController.view.superview.bounds = CGRectMake(0, 0,VC2_WIDTH,VC2_HEIGHT);
}
@end
呈現ViewController1:
ViewController1 *vc1 = [storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:vc1];
navVC.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navVC animated:NO completion:nil];
ViewController2.m
#import "ViewController2.h」
@interface ViewController2()
@end
@implementation ViewController2
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.view.superview.bounds = CGRectMake(0, 0, VC2_WIDTH, VC2_HEIGHT);
}
- (void)nextTapped:(id)sender {
ViewController3 *vc3 = [storyboard instantiateViewControllerWithIdentifier:@"ViewController3」];
[self.navigationController pushViewController:vc3 animated:NO];
self.navigationController.view.superview.bounds = CGRectMake(0, 0,VC3_WIDTH,VC3_HEIGHT);
}
- (void)backTapped:(id)sender {
self.navigationController.view.superview.bounds = CGRectMake(0, 0,VC1_WIDTH,VC1_HEIGHT);
[self.navigationController popViewControllerAnimated:NO];
}
@end
ViewController3.m
#import "ViewController3.h」
@interface ViewController3()
@end
@implementation ViewController3
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.view.superview.bounds = CGRectMake(0, 0, VC3_WIDTH, VC3_HEIGHT);
}
- (void)backTapped:(id)sender {
self.navigationController.view.superview.bounds = CGRectMake(0, 0,VC2_WIDTH,VC2_HEIGHT);
[self.navigationController popViewControllerAnimated:NO];
}
@end
請注意,如果您將文本輸入字段添加到在模式導航控制器上推送的視圖控制器,對於iOS8,鍵盤演示和解除會自動將其大小調整爲錯誤的大小。不幸的是,我仍然沒有妥善解決這個問題。
您可以通過在viewWillAppear中設置navigationController?.preferredContentSize = CGSize(width:preferredContentSize.width,height:preferredContentSize.height)來解決文本字段問題 – 2017-04-13 02:39:13