Keeping the contentOffset in a UICollectionView while rotating Interface Orientation

后端 未结 24 1407
野性不改
野性不改 2020-12-04 07:22

I\'m trying to handle interface orientation changes in a UICollectionViewController. What I\'m trying to achieve is, that I want to have the same contentOffset afte

24条回答
  •  猫巷女王i
    2020-12-04 08:07

    You might want to try this untested code:

    - (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation
                                     duration: (NSTimeInterval)         duration
    {
        [UIView animateWithDuration: duration
                          animation: ^(void)
         {
           CGPoint newContentOffset = CGPointMake(self.scrollPositionBeforeRotation.x *
                                                  self.collectionView.contentSize.height,
                                                  self.scrollPositionBeforeRotation.y *
                                                  self.collectionView.contentSize.width);
           [self.collectionView setContentOffset: newContentOffset
                                        animated: YES];
         }];
    }
    

提交回复
热议问题