在 Xcode 6.1.1、iOS 8.1 SDK 上的 Storyboard 中,静态或原型 UITableViewCell 子视图的大小调整不正确 [英] Static or Prototype UITableViewCell subviews are resized incorrectly in Storyboard on Xcode 6.1.1, iOS 8.1 SDK

查看:32
本文介绍了在 Xcode 6.1.1、iOS 8.1 SDK 上的 Storyboard 中,静态或原型 UITableViewCell 子视图的大小调整不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I updated to Xcode 6.1 earlier and 6.1.1 today. I notice that there's an issue while using Static / Prototype UITableViewCell (or Prototype UICollectionViewCell) in Storyboard. All the subviews with certain Autoresizing masks will be resized incorrectly when running on device / simulator.

UISlider 作为静态 UITableViewCell 的子视图

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

观察Slider时间过长,右侧离开屏幕

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

I already submitted a bugreport to Apple. Hope to receive a response soon.

推荐答案

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

I had the same problem, and have found a solution that works for me. It seems like Xcode is not (always) recording the initial frame sizes of table view cells and their content views.

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

If you open the storyboard in another editor (preferably with Xcode closed), and have a look at your cells you should find the following:

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

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

A number of keys and attributes above have been omitted for brevity. What is missing from the above is rect keys for the tableViewCell and the tableViewCellContentView. Autoresizing relies on the initial frame size to determine offsets from the right/bottom. Without the initial frame size (given by the rect keys) the initial frame is calculated as 0,0,0,0 which doesn't affect items anchored to the top or left, but does (of course) affect items anchored to the right/bottom.

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

To fix the issue ensure there is a (correct) rect key for every tableViewCell and tableViewCellContentView, e.g.:

<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"/>

如果您为单元格启用了辅助视图,则可能需要减小该单元格的内容视图的宽度.Xcode 中显示的内容视图的宽度/高度(变灰)是应该放入故事板(手动)的内容.

If you have an accessory view enabled for a cell you might need to reduce the content view's width for that cell. The width / height shown in Xcode (greyed out) for the content view is what should be put in to the storyboard (by hand).

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

I should add that Xcode does not appear to remove these rect keys from the storyboard when editing, so after edits are complete the storyboard should still be entirely editable with Xcode.

这篇关于在 Xcode 6.1.1、iOS 8.1 SDK 上的 Storyboard 中,静态或原型 UITableViewCell 子视图的大小调整不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆