ios - Setting rootViewController on UIWindow changes UIScrollView with paging layout -
update
it turns out code below not problem. in app delegate doing:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; self.viewcontroller = [[viewcontroller alloc] init]; self.window.rootviewcontroller = self.viewcontroller;// <-- not work //[self.window addsubview:self.viewcontroller.view]; // <-- works [self.window makekeyandvisible]; return yes; } if remove statement "self.window.rootviewcontroller = self.viewcontroller" , add viewcontroller's view window, works. can explain this? setting rootviewcontroller on window constrain child's bounds? have tried go through docs, doesn't mention this.
original post
i having trouble adding padding pages in uiscrollview. trying setup simple scroll view shows uiviews in different pages separated predefined padding (kind of photos app without photos). have been trying follow apple's scrollview example wwdc 2010 , sample app photoscroller come padding showing in view. app hides status bar , adds 1 view controller window. make things simple, each of pages should show uiview colored green, while space there padding yellow. should see yellow when user scrolling. here first 3 pages:

i have single class level field called pagingscrollview declared in .h file. in single view controller, trying follow sample code doing.
#define padding 10 #define page_count 3 - (void)loadview { cgrect pagingscrollframe = [[uiscreen mainscreen] bounds]; pagingscrollframe.origin.x -= padding; pagingscrollframe.size.width += (2 * padding); pagingscrollview = [[uiscrollview alloc] initwithframe:pagingscrollframe]; pagingscrollview.pagingenabled = yes; pagingscrollview.backgroundcolor = [uicolor yellowcolor]; pagingscrollview.contentsize = cgsizemake(pagingscrollframe.size.width * page_count, pagingscrollframe.size.height); self.view = pagingscrollview; for(int = 0; < page_count; i++) { cgrect frame = [self frameforpageatindex:i]; uiview *page = [[uiview alloc] initwithframe:frame]; page.backgroundcolor = [uicolor greencolor]; [pagingscrollview addsubview:page]; } } - (cgrect)frameforpageatindex:(nsuinteger)index { cgrect bounds = pagingscrollview.bounds; cgrect pageframe = bounds; pageframe.size.width -= (2 * padding); pageframe.origin.x = (bounds.size.width * index) + padding; return pageframe; } the pagingscrollframe has width of 340, (i thought) scroll view broken pages of 340 pixels. missing?
looking @ briefly, appears doing things correct, except setting of content size. set:
pagingscrollview.contentsize = cgsizemake(pagingscrollframe.size.width * page_count, pagingscrollframe.size.height); this correct if each of pages right next each other, adding 10pt pad between each view, should have like:
pagingscrollview.contentsize = cgsizemake(pagingscrollframe.size.width * page_count + padding * (page_count - 1), pagingscrollframe.size.height); this should correct problem , cause yellow not in visible area.
Comments
Post a Comment