ios - Last Cell in UICollectionView is clipped -


i have uicollectionview displays vertical list of cells. it's tableview i'm using collection view more controller of how each cell placed in view. reason, last cell in collection view clipped. can drag see bottom half, let go collection view bounces place, obscuring bottom half of last cell. have xib contains collectionview, , register collection view cells xib. whole view placed in navigation controller programmatically. thoughts has issue autolayout. since i'm adding view controller containing collection view navigation controller programmatically, no constraints set between collection view , navigation bar. if hide instantiated navigation bar , drag 1 out in ib, collection view cell not clipped. don't want way. i've tried programmatically adding constraints, doesn't work either. have suggestions? here's how i'm creating navigation controller , placing view controller containing collection view it. also, code i've tried use add constraints include. time being, i'm doing in app delegate in didfinishlaunchingwithoptions:

self.homeviewcontroller = [[ffhomeviewcontroller alloc] init]; ffnavigationpanelviewcontroller *navigationcontroller = [[ffnavigationpanelviewcontroller alloc] init]; uinavigationcontroller *frontnavigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:self.homeviewcontroller]; //    frontnavigationcontroller.navigationbarhidden = yes; uinavigationcontroller *rearnavigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:navigationcontroller];   nslayoutconstraint *topconstraint = [nslayoutconstraint constraintwithitem:self.homeviewcontroller.collectionview attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.homeviewcontroller.navigationcontroller.navigationbar attribute:nslayoutattributebottom multiplier:1.0 constant:0.0];  [self.viewcontroller.frontviewcontroller.view addconstraint:topconstraint]; 

i ran similar issue. problem stems fact uicollectionview subclass of uiscrollview , reason amount of space assigned content not getting updated correspond actual number of cells have.

in case, single column of items, need set contentsize of uicollectionview match amount of space need virtually display of uicollectionviewcells.

assuming cells 100 px high , have 1 section, add following viewwillappear in view controller:

int itemcount = [self.collectionview numberofitemsinsection:0]; float contentheight = (100*itemcount)+100; cgrect screenframe = [[uiscreen mainscreen]bounds]; self.collectionview.contentsize = cgsizemake(screenframe.size.width, frameheight); 

adding 100 allows empty space @ end when scroll bottom.

side note: may have run odd bug here. when put these calculations of of viewwillload|viewwillappear|viewdidappear didn't seem take effect, strangely, putting numberofitemsinsection does work. that's not right place may side effect of loading collectionview xib rather creating programmatically.

and final followup: putting contentsize code viewwilllayoutsubviews seems appropriate behaviour.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -