1

In my project I had created a custom layout for UICollectionView. In that layout, vertical scrolling is NOT possible, only horizontal scrolling is possible.

If that UIViewController is the only thing in the storyboard, layout is working perfectly, ie, there is no vertical scrolling, only horizontal scrolling is possible.

But if you add UINavigationController to storyboard, layout fails in iOS 7 (tested in simulator and device). Then vertical scrolling is ENABLED. You can scroll a little amount, may be 20 or 30 points.

But for iOS 6, layout is working perfectly with and without UINavigationController.(tested in iPhone).

Please help.

Thanks,

SOLUTION

I found solution to this.

In iOS 7, some inset was adding automatically to UICollectionView. So to fix it, add following code to ViewController self.automaticallyAdjustsScrollViewInsets = NO;

I found solution from https://stackoverflow.com/a/18989755/3117930

Hope this is helpful to someone Thanks,

Community
  • 1
  • 1
varsim
  • 70
  • 9

1 Answers1

1

what I can tell it tries to focus on the cell that was closest to the center of the pre-transition view layout. However, if there doesn't happen to be a cell at the center of the view pre-transition then it still tries to center where the cell would be post-transition. This is very clear if you set alwaysBounceVertical/Horizontal to YES, load the view with a single cell and then perform a layout transition.

I was able to get around this by explicitly telling the collection to focus on a specific cell (the first cell visible cell, in this example) after triggering the layout update.

[self.collectionView setCollectionViewLayout:[self generateNextLayout] animated:YES];

// scroll to the first visible cell
if ( 0 < self.collectionView.indexPathsForVisibleItems.count ) 
{
    NSIndexPath *firstVisibleIdx = [[self.collectionView indexPathsForVisibleItems] objectAtIndex:0];
    [self.collectionView scrollToItemAtIndexPath:firstVisibleIdx atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:YES];
}

Hopefully this will help you.

Maverick
  • 319
  • 2
  • 13
Irfan
  • 4,301
  • 6
  • 29
  • 46
  • thanks for quick response. I tried as you told. It didn't fixed my issue. – varsim Feb 26 '14 at 06:16
  • You welcome. Here are some links kindly check them out may they resolve your problem http://stackoverflow.com/questions/20234915/how-to-stack-uicollectionview-sections http://www.techotopia.com/index.php/An_iOS_7_Storyboard-based_Collection_View_Tutorial http://www.techotopia.com/index.php/An_Overview_of_iOS_7_Collection_View_and_Flow_Layout – Irfan Feb 26 '14 at 06:23