我花了一些时间处理同样的问题。在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