ios - Serious bug for UICollectionViewFlowLayout: minimumInteritemSpacing and minimumLineSpacing in horizontal scrolling mode -



ios - Serious bug for UICollectionViewFlowLayout: minimumInteritemSpacing and minimumLineSpacing in horizontal scrolling mode -

i facing next bug uicollectionview in horizontal scrolling mode (ios 8, ios 7, ones have tested).

my question

i have views on bug , on how elegantly solve it.

the setting up uicollectionviewflowlayout * layout ; layout = [[uicollectionviewflowlayout alloc] init] ; layout.scrolldirection = uicollectionviewscrolldirectionhorizontal ; layout.minimuminteritemspacing = 5 ; layout.minimumlinespacing = 100 ; the bug

it's hard explain best. bug happens when cells in uicollectionview not have same sizes.

when cells have same size, looks

but 1 of cells have different size others, looks

so, seems interchanges minimuminteritemspacing , minimumlinespacing.

link minimal non-working example

https://github.com/colasjojo/test_collection_view_bug

more code #import "viewcontroller.h" #import "mycell.h" @interface viewcontroller () @property (weak, nonatomic) iboutlet uiview *viewforcollectionview; @property (nonatomic, assign, readwrite) nsinteger selectedindex ; @end @implementation viewcontroller // // /**************************************/ #pragma mark - init /**************************************/ - (id)initwithcoder:(nscoder *)adecoder { self = [super initwithcoder:adecoder] ; if (self) { [self configure] ; } homecoming self ; } - (instancetype)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil] ; if (self) { [self configure] ; } homecoming self ; } - (void)configure { _selectedindex = -1 ; } // // /**************************************/ #pragma mark - life cycle /**************************************/ - (void)viewdidload { [super viewdidload]; uicollectionviewflowlayout * layout ; layout = [[uicollectionviewflowlayout alloc] init] ; layout.scrolldirection = uicollectionviewscrolldirectionhorizontal ; layout.minimuminteritemspacing = 5 ; layout.minimumlinespacing = 100 ; uicollectionview * collectionview ; cgrect frame ; frame.size = self.viewforcollectionview.frame.size ; collectionview = [[uicollectionview alloc] initwithframe:frame collectionviewlayout:layout] ; collectionview.datasource = self ; collectionview.delegate = self ; collectionview.backgroundcolor = [uicolor clearcolor] ; [collectionview registernib:[uinib nibwithnibname:nsstringfromclass([mycell class]) bundle:nil] forcellwithreuseidentifier:@"mycell"] ; [self.viewforcollectionview addsubview:collectionview] ; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } // // /**************************************/ #pragma mark - datasourcing /**************************************/ - (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { homecoming 100 ; } - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { mycell * cell ; cell = [collectionview dequeuereusablecellwithreuseidentifier:@"mycell" forindexpath:indexpath] ; cell.label.text = [@([indexpath indexatposition:1]) stringvalue] ; ; homecoming cell ; } - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath { if ([indexpath indexatposition:1] == self.selectedindex) { homecoming cgsizemake(200, 200) ; } else { homecoming cgsizemake(110, 110) ; } } - (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath { nsmutablearray * indexes = [nsmutablearray new] ; if (self.selectedindex >= 0) { [indexes addobject:[nsindexpath indexpathforitem:self.selectedindex insection:0]] ; } if (self.selectedindex != [indexpath indexatposition:1]) { [indexes addobject:indexpath] ; self.selectedindex = [indexpath indexatposition:1] ; } else { self.selectedindex = -1 ; } [collectionview reloaditemsatindexpaths:indexes] ; } @end

ios objective-c uicollectionview uicollectionviewlayout uicollectionviewdelegate

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -