How can a get the auto layout size of the UICollectionViewCells in iOS 8? (systemLayoutSizeFittingSize returns size with zero height in iOS 8)

后端 未结 8 522
心在旅途
心在旅途 2021-01-30 14:21

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

Here\'s what the code

相关标签:
8条回答
  • 2021-01-30 14:51

    This is a bug in xCode6 and iOS 8 SDK running on iOS7 devices :) It almost waisted my day. Finally it worked with the below code in the UICollectionViewCell sub class. I hope this will be fixed with the next version

    - (void)setBounds:(CGRect)bounds {
        [super setBounds:bounds];
        self.contentView.frame = bounds;
    }
    
    0 讨论(0)
  • 2021-01-30 14:55

    It was a bug in iOS 8 beta versions. Finally it is fixed with for iOS 8 GB (Build 12A365). So for me now it works with the same code I wrote for iOS 7. (see the question)

    0 讨论(0)
  • 2021-01-30 14:56

    I had the same issue for UITableViewCells and iOS 7 (ios8 works perfectly), but "Triet Luong" solution worked for me:

    return [sampleCell.containerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    
    0 讨论(0)
  • 2021-01-30 15:03

    What you need to do is wrap all of your content in a container view, then call:

    return [sampleCell.containerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    

    Your cell should look like this: cell -> containerView -> sub views

    This works on both ios7 & ios8.

    Supposedly on ios8, all you have to do is set the estimateSize & cell will automatically auto size on its own. Apparently that's not working as of beta 6.

    0 讨论(0)
  • 2021-01-30 15:08

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

    Will report back when Beta 6 is out.

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

    0 讨论(0)
  • 2021-01-30 15:11

    maybe you have some wrong constrain, you should specify both virtical top space and bottom space between your UIView and contentView, i also had this issue before, that is because i just specified the virtical top space, and didn't specfied the virtical bottom space to contentView

    0 讨论(0)
提交回复
热议问题