一个怎样才能获得UICollectionViewCells的自动布局大小的iOS 8? (systemLayoutSizeFittingSize零高度的iOS 8返回的大小) [英] How can a get the auto layout size of the UICollectionViewCells in iOS 8? (systemLayoutSizeFittingSize returns size with zero height in iOS 8)

查看:724
本文介绍了一个怎样才能获得UICollectionViewCells的自动布局大小的iOS 8? (systemLayoutSizeFittingSize零高度的iOS 8返回的大小)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于iOS的8 [UIColletionViewCell systemLayoutSizeFittingSize:UILayoutFittingCom pressedSize] 返回一个大小为0高度

Since iOS 8 [UIColletionViewCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize] returns a size with height of 0.

这里的code做了什么:

要确定大小的单元格的 UICollectionView 在iOS的7我使用 systemLayoutSizeFittingSize:在定义的细胞使用自动布局厦门国际银行文件。大小取决于字体大小的的UILabel 我在厦门国际银行文件是的 UICollectionViewCell A子视图。标签的字体设置为 UIFontTextStyleBody 。因此,基本上该单元格的大小取决于在IOS 7取得的字体大小设置

To determine the size for cell in a UICollectionView in iOS 7 I use systemLayoutSizeFittingSize: on a cell defined in a xib file using auto layout. The size depends on the font size of an UILabel being a subview of the UICollectionViewCell in my xib file. The label's font is set to UIFontTextStyleBody. So basically the cell's size depends on the font size setting made in iOS 7.

这里是code本身:

+ (CGSize)cellSize {
    UINib *nib = [UINib nibWithNibName:NSStringFromClass([MyCollectionViewCell class]) bundle:nil];

    // Assumption: The XIB file only contains a single root UIView.
    UIView *rootView = [[nib instantiateWithOwner:nil options:nil] lastObject];

    if ([rootView isKindOfClass:[MyCollectionViewCell class]]) {
        MyCollectionViewCell *sampleCell = (MyCollectionViewCell*)rootView;
        sampleCell.label.text = @"foo"; // sample text without bar

        [sampleCell setNeedsLayout];
        [sampleCell layoutIfNeeded];

        return [sampleCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    }

    return CGSizeZero;

}

它工作在iOS的7完美的罚款,但不是在iOS的8不幸的是我不知道为什么。

It works perfectly fine in iOS 7 but not in iOS 8. Unfortunately I have no clue why.

PS:

 return [sampleCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];

而不是

 return [sampleCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];

正如有人可能会建议,并没有任何区别。

as somebody might suggest, doesn't make any difference.

推荐答案

看起来像这样正式的错误:我申请已关闭作为的这个

Looks like this officially a bug: I filed a report that was closed as a duplicate of this one

将报告回来时,测试6出去了。

Will report back when Beta 6 is out.

[更新:在iOS中8的转基因种子正常工作,且该bug已被苹果封闭]

[Update: working properly in the GM seed of iOS 8, and the bug has been closed by Apple.]

这篇关于一个怎样才能获得UICollectionViewCells的自动布局大小的iOS 8? (systemLayoutSizeFittingSize零高度的iOS 8返回的大小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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