lxcid / LXReorderableCollectionViewFlowLayout

Extends `UICollectionViewFlowLayout` to support reordering of cells. Similar to long press and pan on books in iBook.
http://lxcid.com/
MIT License
1.86k stars 328 forks source link

trying to add a zoom slider to the collection #29

Closed boozi2 closed 11 years ago

boozi2 commented 11 years ago

hey everyone,

i love this reorderable flowlayout and i tried to use it in a project where im changing the cell sizes with a uislider.

everything works grate until the cells are reaching a size where they can fit only one per line.

then the following thing happens: screen shot 2013-05-02 at 6 28 29 pm

does anyone have any idea why this happens ?

to enable zooming i added the following code to the sample demo with the cards:

in LXCollectionViewController.h file

@property (strong, nonatomic) UISlider *zoomController; @property (nonatomic) CGFloat zoomLevel;

and in LXCollectionViewController.m file

-(IBAction)sliderValueChanged:(UISlider *)sender { self.zoomLevel = self.zoomController.value; [self.collectionView reloadData]; [self.collectionView.collectionViewLayout invalidateLayout]; }

}

-(void) addZoomController { self.zoomController = [[UISlider alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, self.view.frame.size.width, 50)]; [self.zoomController addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];

self.zoomController.minimumValue = -400;
self.zoomController.maximumValue = 400;

self.zoomLevel = 0;
[self.view addSubview:self.zoomController];

}

lxcid commented 11 years ago

If you fork and branch out a version with the behavior you specify, I can pull and try see if I can diagnostic the issue. :)

boozi2 commented 11 years ago

lxcid, thanks for the fast reply !

my fork is here : https://github.com/boozi2/LXReorderableCollectionViewFlowLayout.git

lxcid commented 11 years ago

Thanks for the help!

I went to do some debugging and found out that if the width and/or height is odd, the UICollectionView will display incorrectly, but if the width and/or height is even, the UICollectionView display correctly. This portion doesn't seems like something the library controls though, to me it seems like UICollectionView issue. If I set the UICollectionView layout to the default one, it still happening. I think a work around is just do an increment of 2.

screen shot 2013-05-03 at 12 42 43 am screen shot 2013-05-03 at 12 42 06 am screen shot 2013-05-03 at 12 42 21 am screen shot 2013-05-03 at 12 42 30 am

boozi2 commented 11 years ago

Thanx lxcid, its a strange bug that the cell's measurements should always be even.. anyway the workaround does the trick !

thanx again for this great layout