Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable focus triggered scrolling of UICollectionView

Is there a way to disable automatic scrolling of the UICollectionView when cell gets focused? I want to adjust the content offset of the cell manually when it gets into focus.

I wan't to update the content offset in:

- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context
       withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
    [coordinator addCoordinatedAnimations:^
     {
         [UIView animateWithDuration:[UIView inheritedAnimationDuration]
                          animations:^
          {
              // Move next focused cell.
              if ([context.nextFocusedView isKindOfClass:[YBZEventCollectionViewCell class]])
              {
                  UICollectionViewCell *cell = (UICollectionViewCell *)context.nextFocusedView;

                  CGPoint offset = CGPointMake(CGRectGetMinX(cell.frame), 0.0f);

                  [_collectionView setContentOffset:offset];
              }
          }];

     } completion:nil];
}

This works but since the focus engine also moves my cell (scrolls it) I end up with animation which is not smooth, there is a "kick" at the end of it.

like image 238
Rafa de King Avatar asked Nov 04 '15 14:11

Rafa de King


1 Answers

Just ran into this exact thing. To disable automatic scrolling of a UICollectionView when focus changes, just disable scrolling in the 'Scroll View' properties for the collection view in interface builder:

enter image description here

like image 68
David Haynes Avatar answered Sep 21 '22 01:09

David Haynes