ios - Full screen horizontally scrolling UICollectionView cells shift downwards when used in first displayed UIViewController -
i'm creating series of pages display when user first starts app. this, have programatically set uiviewcontroller initializes (programatically set up) uicollectionview size of view controller bounds. each cell contains fullscreen sized image.
when view controller pushed when there's existing view controller, shows fine. but, when view controller used initial root view controller app navigation controller, collection view has correct size , alignment, cells shifted down 10 pixels top of screen, collection view background shows through.
(note red collection view background color)
if set collection view in viewdidload, viewdidlayoutsubviews, or viewwillappear, same problem. don't encounter issue if set collection view in viewdidappear, doesn't work because user see black screen before collection view loads.
here code displaying view controller, in application:didfinishlaunchingwithoptions:launchoptions:
uiviewcontroller* viewcontrollertopush = [[onboardingviewcontroller alloc] initwithnibname:nil bundle:nil]; _nav = [[uinavigationcontroller alloc] initwithrootviewcontroller:viewcontrollertopush]; [_nav setnavigationbarhidden:yes]; self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; [self.window setrootviewcontroller:_nav]; [self.window makekeyandvisible]; and here code setting collection view , layout:
uicollectionviewflowlayout* layout = [[uicollectionviewflowlayout alloc] init]; layout.minimuminteritemspacing = 0; layout.minimumlinespacing = 0; layout.itemsize = cgsizemake(self.view.bounds.size.width, self.view.bounds.size.height); layout.scrolldirection = uicollectionviewscrolldirectionhorizontal; cgrect collectionviewframe = self.view.bounds; _collectionview = [[uicollectionview alloc] initwithframe:collectionviewframe collectionviewlayout:layout]; _collectionview.delegate = self; _collectionview.datasource = self; _collectionview.pagingenabled = yes; _collectionview.showshorizontalscrollindicator = no; [_collectionview registerclass:[onboardingcollectionviewcell class] forcellwithreuseidentifier:@"cell"]; [self.view addsubview:_collectionview];
i fixed issue setting view controller's automaticallyadjustsscrollviewinsets no in init function. https://stackoverflow.com/a/25352483/1370967 inspiration on this.
Comments
Post a Comment