过去几个小时我一直在努力解决这个问题,搜索SO仍然无济于事。
我有一个UIViewController,里面有一个Container视图(从Storyboards中拖入)。容器视图有一个关联的类,它选择要显示的另外两个视图控制器之一。
-(void)setDisplayMode:(EventsDisplayMode)displayMode {
switch (displayMode) {
case EventsDisplayModeGrid: {
// show grid
if (!gridViewController) {
gridViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"gridViewController"];
}
[UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
if (listViewController)
[listViewController.view removeFromSuperview];
gridViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:gridViewController.view];
listViewController = nil;
} completion:^(BOOL finished) {
}];
break;
}
case EventsDisplayModeList: {
// show list
if (!listViewController)
listViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"listViewController"];
[UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
if (gridViewController)
[gridViewController.view removeFromSuperview];
[self.view addSubview:listViewController.view];
gridViewController = nil;
} completion:^(BOOL finished) {
}];
break;
}
}
}
以上是容器视图控制器中的代码。当设置任何一种模式时,视图会轻微地从iPhone 5s上的屏幕底部流出,而在iPhone 4S上,就好像内部视图根本没有为设备调整大小。我已经尝试了各种组合来调整视图大小 - 在每个控制器的Storyboard中设置约束,从视图的高度手动取消数量 - 似乎没有任何效果。有什么明显的东西我不见了吗?