这让我发疯。我有一个标签栏 Controller ,它被插入导航 Controller 堆栈。
标签栏的第一个 View Controller 有一个图像,它有两个约束:
- 0 到顶部布局指南
- 0 到底部布局指南
但是当标签栏 Controller 被推送时,第一个 View Controller 第一次出现时,上述图像无特殊原因偏移了 20 像素。
最佳答案
我已经通过执行以下操作修复了它:
- (void)viewDidLayoutSubviews {
//I need to do this, otherwise the scrollview is offset by 20 pixels when first displayed (I HAVE NO IDEA WHY....)
if (self.scrollView.frame.origin.y == 20) {
[self.scrollView setFrame:CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height + 20)];
}
}
虽然我不知道为什么它只会在第一次显示时出错......
关于ios - TabBarController - 第一个 View 偏移 20px,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21725010/