【问题标题】:Autolayout debug build differs from release build自动布局调试版本与发布版本不同
【发布时间】:2018-09-08 16:34:12
【问题描述】:

我有一个包含 UITableview 的容器视图。通过调试构建,一切看起来都不错-

但是随着发布构建,childviewcontroller 出现 inset-

这是容器视图的故事板-

这是实例化视图的代码-

self.dailyWeatherTableViewController=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"DailyForecastViewController"];
self.dailyWeatherTableViewController.view.frame =self.view.frame;
UIEdgeInsets newSafeArea;
newSafeArea.top=self.headerView.frame.size.height;
if (@available(iOS 11.0, *)) {
    self.dailyWeatherTableViewController.additionalSafeAreaInsets=newSafeArea;
} else {
    // Fallback on earlier versions
}
[self addChildViewController:self.dailyWeatherTableViewController];
[self.forecastContainerView addSubview:self.dailyWeatherTableViewController.view];
[self.dailyWeatherTableViewController didMoveToParentViewController:self];

视图层次结构调试器显示 UITableviewCellContentView 的封装布局宽度设置为 261。一些谷歌搜索似乎表明这与视图的自动调整掩码有关,但更改此设置或在 cellforindex 方法中设置视图的框架并不能解决此问题。

这是tableview约束的截图-

【问题讨论】:

  • 哪些元素的尺寸不正确?为您的视图提供不同的背景颜色,以便您可以清楚地看到元素的框架。
  • 我用视图层次调试器做了一些挖掘,看起来罪魁祸首可能是单元格的内容视图,但我不知道如何修复它。请参阅上面的问题编辑。
  • 很难说...我假设您没有收到任何自动布局警告/错误? encapsulated-layout width 有可能(可能?)被 tableView 的宽度设置/强制... tableView 本身看起来如何(在调试视图层次结构中)?
  • 另外你说“这里是实例化视图的代码”但是在哪里呢?您确实意识到viewDidLoad 绝对是错误的地方这样做????除非您提供自动调整大小或自动布局,但您似乎都没有这样做。
  • @DonMag uitableviewcontroller 和单元格在 375 处似乎已满,但 contentview 为 261。

标签: ios uitableview autolayout storyboard uicontainerview


【解决方案1】:

看来罪魁祸首是容器的附加安全区域Insets。左右加0后,边距固定-

`if (@available(iOS 11.0, *)) {
    UIEdgeInsets newSafeArea;
    newSafeArea.top=self.headerView.bounds.size.height;
    newSafeArea.right=0;
    newSafeArea.left=0;
    newSafeArea.bottom=0;
    self.dailyWeatherTableViewController.additionalSafeAreaInsets=newSafeArea;
}`

我仍然不确定为什么这是必要的,因为苹果示例没有这样做-https://developer.apple.com/documentation/uikit/uiview/positioning_content_relative_to_the_safe_area?language=objc

【讨论】:

    猜你喜欢
    • 2010-10-27
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    相关资源
    最近更新 更多