UICollectionView adds top margin

前端 未结 9 1636
走了就别回头了
走了就别回头了 2020-12-04 14:06

I want to put a UICollectionView control that shows thumbs horizontally (only a single line of thumbs). For some reason the UICollectionView push the thumbs 44 pixels down,

相关标签:
9条回答
  • 2020-12-04 14:43

    Similar to @Sviatoslav answer, you can try the following:

    - (void) viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
    
        yourCollectionView.contentOffset = CGPointMake(0, 0);
    }
    
    0 讨论(0)
  • 2020-12-04 14:46

    You can set this in the storyboard too.

    Make sure you've selected the ViewController, and then untick "Adjust Scroll View Insets".

    enter image description here

    I haven't tested what this IB/Storyboard method does on iOS6 though. With the code method you need to check that the VC responds to the method:

    if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) {
    self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    0 讨论(0)
  • 2020-12-04 14:46

    Swift 5.2 / Xcode 11.3

    viewController.automaticallyAdjustsScrollViewInsets 
    

    has been deprecated since iOS 11.

    My solution:

    collectionView.contentInsetAdjustmentBehavior = .never
    
    0 讨论(0)
提交回复
热议问题