UICollectionView Layout Issue

前端 未结 15 1664
天涯浪人
天涯浪人 2020-12-24 00:17

I am using UICollectionView using the flow layout. I have made a custom UICollectionViewCell for the same. But on running the project the console k

相关标签:
15条回答
  • 2020-12-24 01:03

    It's complaining that the item height is bigger than the height of the collectionView. So it's sticking out. So you have to make the height the same or less. Like this:

        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: collectionView.frame.height, height: collectionView.frame.height)
        
    }
    

    Using the height for the width makes it a square. This is assuming inset is 0 which it should be if you haven't done anything.

    0 讨论(0)
  • 2020-12-24 01:04

    Be sure to set the right autoresizing mask for UICollectionView and UICollectionviewcell. This fixed my problem for iPhone 4 Simulator

    0 讨论(0)
  • 2020-12-24 01:11

    I found that, using storyboards, you have to go into the storyboard and click on the overall View Controller (the view should be highlighted in blue) and go to the Attributes Inspector (the fourth tab on the right side of the screen) and unchecking the "Under Top Bars", "Under Bottom Bars", and "Under Opaque Bars." This cleared up the issue for me, and it cleared it for my coworkers as well.

    0 讨论(0)
  • 2020-12-24 01:13

    If you are using storyboards and auto layout, debugging this kind of problems is really hard...

    I had similar problem when trying to display UICollectionViewCell fullscreen on iPhone.

    Most of the time issue is with the size of the cell set in

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)
    

    or directly on flowLayout.itemSize.

    But... try:

    1. Select the ViewController:

    Selecting View Controller

    1. Then uncheck Extend Edges options:

    Disable Extend Edges Options

    And now try setting your auto layout constraints.

    Good luck.

    0 讨论(0)
  • 2020-12-24 01:14

    I've been having some issues when the using a collection view to present full screen view controllers.

    Basically at run time, it'll ask for the size of the item and simply return the size of the collection view:

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
        return self.collectionView.frame.size;
    }
    
    0 讨论(0)
  • 2020-12-24 01:14

    For me I am using AKPickerView inside of a custom UIView which was giving me a slew of warnings like the ones mentioned here. All I did to eliminate the warnings was to Un-Check the box called 'AutoResize Subviews' in the Attributes Inspector for my custom UIView. That silenced the warnings so hard, I thought my logger stopped working.

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