ios - UIView's frame rendering larger than frame -
i trying add subview uiscrollview. first instantiate view controller storyboard, set view's frame application bounds. when add view uiscrollview, larger it's supposed be.
cgrect mainframe = cgrectmake(0, topbuttonheight, screenwidth, screenheight); feelingvc = (feelingviewcontroller *)[self.storyboard instantiateviewcontrollerwithidentifier:@"feelingvc"]; feelingvc.delegate = self; feelingview = feelingvc.view; [feelingview setframe:mainframe]; [self.scrollview addsubview:feelingview];
i can tell because background color extending past should be. "debug view hierarchy" mode in xcode confirms this. but, if inspect view's frame, prints out should be, not is.
a view of same size, generated programatically, works should:
mainview = [[uiview alloc] initwithframe:mainframe]; mainview.backgroundcolor = [uicolor blackcolor]; [self.scrollview addsubview:mainview];
i'm not sure causing issue - i've instantiated other views view controllers, via storyboard, , set frames without problems.
edit: being called viewdidload of view controller containing uiscrollview. screenwidth & screenheight calculated such (they instance variables):
screenwidth = [uiscreen mainscreen].applicationframe.size.width; screenheight = [uiscreen mainscreen].applicationframe.size.height;
try set view frame in viewwillappear
method.
viewdidload
not place set frames (because called once when view getting loaded.), ui components not configured system yet.
also, prefer use:
screenwidth = [uiscreen mainscreen].bounds.size.width; screenheight = [uiscreen mainscreen].bounds.size.height;
instead of
screenwidth = [uiscreen mainscreen].applicationframe.size.width; screenheight = [uiscreen mainscreen].applicationframe.size.height;
since bounds has correct positional information taking consideration device's orientation in case.
or can this, after initializing mainview inside viewdidload:
method
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; mainview.frame = [uiscreen mainscreen].bounds; }
you can add reconfigure view frame whenever subviews updated:
- (void)viewwilllayoutsubviews { //or viewdidlayoutsubviews [super viewwilllayoutsubviews]; mainview.frame = [uiscreen mainscreen].bounds; }
Comments
Post a Comment