iOS7: UICollectionView appearing under UINavigationBar

后端 未结 5 1139
囚心锁ツ
囚心锁ツ 2021-02-01 06:56

I\'ve been building on iOS 7 for a while now but I\'ve yet to get this solved, I have a number of views with autolayout enabled that were created in Storyboard and are displayed

相关标签:
5条回答
  • 2021-02-01 07:01

    I am using swift and xcode 7.3.1. I solved it by going to story board and selecting my Navigation Controller and then unchecking "Extend Edges" "Under Top Bards".

    0 讨论(0)
  • 2021-02-01 07:04

    FYI if your UICollectionView is the root view in your view controller's hierarchy and your view controller has automaticallyAdjustsScrollViewInsets set to YES (this is the default), then the contentInset should update automatically.

    However, the scrollview's contentInset is only automatically updated if your scrollview (or tableview/collectionview/webview btw) is the first view in their view controller's hierarchy.

    I often add a UIImageView first in my hierarchy in order to have a background image. If you do this, you have to manually set the edge insets of the scrollview in viewDidLayoutSubviews:

    - (void) viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
        CGFloat top = self.topLayoutGuide.length;
        CGFloat bottom = self.bottomLayoutGuide.length;
        UIEdgeInsets newInsets = UIEdgeInsetsMake(top, 0, bottom, 0);
        self.collectionView.contentInset = newInsets;
    
    }
    
    0 讨论(0)
  • 2021-02-01 07:05

    I had this problem before, just set the edge insents of the collection view with a top margin:

     [self.myCollectionVC.collectionView setContentInset:UIEdgeInsetsMake(topMargin, 0, 0, 0)];
    

    Where topMargin is the size of the nav bar, or whatever point you want the collection to start scrolling.

    In this way, your collection view will start scrolling just below the navigation bar, and at the same time it will fill the whole screen and you will see it if your nav bar is translucent.

    0 讨论(0)
  • 2021-02-01 07:13
    -(void) viewDidLoad{
        [super viewDidLoad];
        self.automaticallyAdjustsScrollViewInsets = NO; //added  important
    } 
    
    - (void) viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
        CGFloat top = self.topLayoutGuide.length;
        CGFloat bottom = self.bottomLayoutGuide.length;
        UIEdgeInsets newInsets = UIEdgeInsetsMake(top, 0, bottom, 0);
        self.collectionView.contentInset = newInsets;
    
    }
    
    0 讨论(0)
  • 2021-02-01 07:15

    I had this problem after ios 11, just set the contentInsetAdjustmentBehavior of UICollectionView to never:

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