uitableview - Xcode 6.1.1、iOS 8.1 SDK 上的 Storyboard 中静态或原型(prototype) UITableViewCell subview 的大小调整不正确

标签 uitableview xcode6 uicollectionviewcell autoresize ios8.1

所以我更新到之前的 Xcode 6.1 和今天的 6.1.1。我注意到在 Storyboard中使用静态/原型(prototype) UITableViewCell (或原型(prototype) UICollectionViewCell)时存在问题。在设备/模拟器上运行时,具有某些自动调整大小蒙版的所有 subview 都将错误地调整大小。

UISlider as a subView of the Static UITableViewCell

UISlider 作为静态 UITableViewCell 的 subview

Autoresizing rule is Flexible Width. Or Flexible LeftMargin also causes the problem.

自动调整大小规则是灵活宽度。或者Flexible LeftMargin也会导致问题。

Observing the Slider is too long, went off the screen the the right

观察 slider 太长,右侧超出屏幕

我已经向 Apple 提交了错误报告。希望尽快收到回复。

最佳答案

我遇到了同样的问题,并找到了适合我的解决方案。 Xcode 似乎并不(总是)记录 TableView 单元格及其内容 View 的初始帧大小。

如果您在另一个编辑器中打开 Storyboard(最好关闭 Xcode),并查看单元格,您应该会发现以下内容:

<tableViewCell ...>
   <autoresizingMask .../>
   <tableViewCellContentView ...>

为了简洁起见,上面的一些键和属性已被省略。上面缺少的是 tableViewCelltableViewCellContentViewrect 键。自动调整大小依赖于初始帧大小来确定距右侧/底部的偏移量。如果没有初始帧大小(由 rect 键给出),初始帧将计算为 0,0,0,0,这不会影响锚定到顶部或左侧的项目,但会影响(当然) 影响锚定到右侧/底部的项目。

要解决此问题,请确保每个 tableViewCelltableViewCellContentView 都有一个(正确的)rect 键,例如:

<tableViewCell ...>
   <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
   <autoresizingMask .../>
   <tableViewCellContentView ...>
      <rect key="frame" x="0.0" y="0.0" width="320" height="43"/>

如果您为某个单元格启用了附件 View ,您可能需要减小该单元格的内容 View 的宽度。 Xcode 中显示的内容 View 的宽度/高度(灰色)是应该放入 Storyboard(手动)的内容。

我应该补充一点,在编辑时,Xcode 似乎不会从 Storyboard中删除这些 rect 键,因此编辑完成后, Storyboard应该仍然可以使用 Xcode 完全编辑。

关于uitableview - Xcode 6.1.1、iOS 8.1 SDK 上的 Storyboard 中静态或原型(prototype) UITableViewCell subview 的大小调整不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27265576/

相关文章:

ios - UITableview:固定节标题

ios - 使用 ObjectiveC++ 编译器的问题

swift - 使用 IGListKit 或 UICollectionView 每行多个部分

ios - 有没有办法滚动到集合中选定的 UICollectionViewCell?

swift - 将 UITableview 与订阅数据同步

swift - 如何通过更改单元格的高度来创建动态 TableView 页脚

ios - UITableView 无法使用 Swift 3 中的 Index 正确显示数据

ios - NSDateFormatter dateFormat ShortStyle 不工作

ios8 - xcode 6.1.1无法启动ios模拟器

swift - UIImageView 的角半径不适用于具有动态大小的 UICollectionViewCell