3

I am implementing the split screen feature for the iPad Air 2 and iPad Mini 4. I'm trying to detect when the size of the split screen changes. When running as the primary app, either the viewWillTransitionToSize or willTransitionToTraitCollection will be executed. If my app is running as the secondary app, the viewWillTransitionToSize function is called when opening the secondary app or while in landscape mode, changing from 1/4 to 1/2 of the screen. When I change the secondary app from using 1/2 to 1/4 of the screen, no functions are called to help indicate that change. Is there supposed to be a function called?

Mike Walker
  • 2,944
  • 8
  • 30
  • 62

1 Answers1

2

UPDATE

If you're using UICollectionView you need to draw attention to UICollectionViewLayout method which is called shouldInvalidateLayoutForBoundsChange: Basically this method is called every-time bounds (not size) of your collection view is changed and if you answer YES your collection view relayouts.

To experiment you may (e.g. by subclassing UICollectionViewFlowLayout) override this method like this:

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
    return YES;
}

If it works for you may try some more efficient way to return YES only when actual size is changed. Something like this

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
    BOOL should = !CGSizeEqualToSize(self.collectionView.frame.size, newBounds.size);
    return should;
}

that would be more natural than using viewWillTransitionToSize

ilnar_al
  • 932
  • 9
  • 13
  • In my situation I am using a `UICollectionView` which is used as a photo viewer. So each `UICollectionVIewCell` takes up the entire view. I checked and `viewWillTransitionToSize`, `willTransitionToTraitCollection`, and `traitCollectionDidChange` were not called when changing from 1/4 to 1/2. I can see that `viewWillLayoutSubviews` is called, but is that frown upon to update the `UICollectionView` is doesn't have the desired layout? – Mike Walker Dec 07 '15 at 22:51