Static or Prototype UITableViewCell subviews are resized incorrectly in Storyboard on Xcode 6.1.1, iOS 8.1 SDK

和自甴很熟 提交于 2019-11-30 19:02:46

问题


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 as a subView of the Static UITableViewCell

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

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

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


回答1:


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.

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 ...>

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.

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

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).

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.



来源:https://stackoverflow.com/questions/27265576/static-or-prototype-uitableviewcell-subviews-are-resized-incorrectly-in-storyboa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!