2

Xcode Interface Builder is driving me nuts and I've spent most of my day googling for a solution.

I have a storyboard with a CollectionViewCell that contains a UIImageView. The CollectionViewCell size is 125 x 125 and Autoresize subviews is checked.

The UIImageView has 4 constraints to its superview (leading, trailing, top, bottom), all set to 0. This should ensure that the UIImageView is sized to fill the superview. The UIImageView is sized correctly when the CollectionViewCell is shrunk to a smaller size, but IT DOES NOT WORK when the CollectionViewCell is stretched to a larger size.

EDIT: I've tried the same using a UILabel subview and the same thing happens.

Is this a known problem or is there any way to debug constraints?

Thanks

4

2 に答える 2

1

私はついにhttp://www.nomtek.com/adjusting-your-app-to-ios-8/から問題の完全な解決策を見つけました

まず、Interface Builder で CollectionViewCell の Autoresize Subviews がチェックされていることを確認し、次に ConnectionViewCell サブクラスに次の awakeFromNib メソッドを追加する必要がありました。

- (void)awakeFromNib {

    [super awakeFromNib];

    self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

これら 2 つのことにより、sizeForItemAtIndexPath を使用した動的なセルのサイズ変更でも、セルの内容 (UIImageView と UILabel) が適切に引き伸ばされます。

于 2014-10-19T10:53:06.610 に答える