TeehanLax / UICollectionView-Spring-Demo

A demonstration of UICollectionView and UIKit Dynamics
MIT License
471 stars 71 forks source link

Layout Issues After Enabling Device Rotation #2

Closed bryanluby closed 11 years ago

bryanluby commented 11 years ago

If I enable device rotation in build settings, some collectionViewCells are rendered partially off-screen after rotating the device.

Steps:

  1. Rotate to landscape
  2. Scroll down a bit
  3. Rotate back to portrait

photo

ashfurrow commented 11 years ago

Great find! I'm out of town at the moment but will take a look when I get back.

In the mean time, feel free to take a crack at it and issue a pull request :beers:

bryanluby commented 11 years ago

I'm a bit stuck on this. I've tried explicitly calling [self.collectionViewLayout invalidateLayout] and prepareLayout from inside the view controller during a rotation by implementing didRotateFromInterfaceOrientation, but it doesn't seem to have any effect.

I also tried tracking rotation inside the layout class by creating a property for storing the current UIDeviceOrientation. Every time prepareLayout is called I envoked [[UIDevice currentDevice] orientation] and checked if the new orientation is different from the current property's orientation . This doesn't seem like the best approach though since UIDeviceOrientation also includes FaceUp, FaceDown, etc.

ashfurrow commented 11 years ago

@bryanluby Here's my fix. Not the most elegant, but that sort of approach will work. You could also compare the bounds size, which would probably be preferable.

The trick is to remove the behaviours from the dynamic animator to force them to be re-added in prepareLayout. Does that make sense?

ashfurrow commented 11 years ago

When you've had a chance to look over the Pull Request #3 , let me know.

bryanluby commented 11 years ago

Thanks, I looked at Pull Request #3. It works and it makes perfect sense to remove all behaviors from the dynamic animator after detecting an orientation change.

ashfurrow commented 11 years ago

Great! I've merged the PR. Thanks for opening the issue!