【发布时间】:2019-08-28 01:57:44
【问题描述】:
我正在做一个我没有开始的项目,现在我们在第一个 VC 上发现了一个错误:
第一个视图控制器有一个顶栏菜单和一个底栏菜单。剩下的是一个容器视图,它显示了所需的视图控制器。
在viewDidLoad这个方法被调用:
self.currentIndex = 0;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGRect contentViewFrame = screenBounds;
// iPhone X
if (@available(iOS 11.0, *)) {
UIWindow *window = [UIApplication sharedApplication].keyWindow;
CGFloat topPadding = window.safeAreaInsets.top;
CGFloat bottomPadding = window.safeAreaInsets.bottom;
contentViewFrame.origin.y = topPadding + 20.0; // 20 p for status bar
contentViewFrame.size.height -= (rootView.bottomBarView.frame.size.height + (topPadding + 20.0) + bottomPadding); // topPadding + 20 statusbar
} else {
contentViewFrame.size.height -= rootView.bottomBarView.frame.size.height;
}
self.conversationVC = [[VOCConversationVC alloc] initWithFrame: contentViewFrame];
self.diaryVC = [[VOCDiaryVC alloc] initWithFrame: contentViewFrame];
self.managementVC = [[VOCManagementVC alloc] initWithFrame: contentViewFrame];
self.viewControllerSelected = VOCViewControllerSelectedCommunication;
}
事情在ViewDidLoad点,topPadding和bottomPadding仍然是0,因此没有正确设置帧。
如果我之后更改contentViewFrame 高度,它不会对视图产生任何更改。我试过了:
viewDidLayoutSubviews
layoutIfNeeded
layoutSubviews
以及其他一些没有帮助的方法。当我打印 contentViewFrameheight 时,它发生了变化,但没有明显的效果,所以我错过了我做错了什么......也许上述方法之一我没有使用正确的视图或在正确的时刻?还是别的什么?
谢谢
【问题讨论】:
标签: ios objective-c autolayout size screen