Static or Prototype UITableViewCell subviews are r

2020-03-07 04:57发布

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

UISlider as a subView of the Static UITableViewCell

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

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

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条回答
做自己的国王
2楼-- · 2020-03-07 05:52

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.

查看更多
登录 后发表回答