Featured post
iphone - Why do I have to subtract for height of UINavigationBar twice to get UIWebView to be correct size? -
i using uinavigationbar in app 3 different uiviewcontrollers. rootviewcontroller hides navigation bar when view on top of stack implementing following in rootviewcontroller.m:
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; [self.navigationcontroller setnavigationbarhidden:true animated:true];}
and
- (void)viewwilldisappear:(bool)animated { [super viewwilldisappear:animated]; [self.navigationcontroller setnavigationbarhidden:false animated:true];}
when firstviewcontroller pushed top, works fine. in ib, told view has status bar , navigation bar. of subviews (added in ib) laid out expected on simulator , on device.
however, when secondviewcontoller pushed top, things weird. in ib, told view there status bar , navigation bar before. added uiwebview fill remainder of screen (verified dimensions of 320 x 416 in ib) , looks correct in ib. ran app on simulator , device, , uiwebview runs behind navigation bar if 320 x 460.
to fix problem, added code secondviewcontroller.m:
- (void)viewdidload { [super viewdidload]; [webview setframe:cgrectmake(0.0, 44.0, 320.0, 372.0)]; }
and looks fine when running on simulator , device. isn't right! height 416, not 372. why did have subtract height of uinavigationbar twice? hack works, think there important i'm missing here need understand. ideas appreciated.
not entirely sure why you're having subtract height twice, can explain why have @ all.
basically, in viewdidload
, view controller , associated view have no idea they'll used. means view has no superview. if set frame before view controller presented modally, added navigation stack, or presented in tab bar, view liable moved around , resized , kinds of crazy stuff. answer problem perform layout in viewwillappear:
instead:
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; webview.frame = self.view.bounds; }
that snippet of code adjust web view fill area taken view controller, , execute before presenting view on screen. when executes, self.view
has been adjusted account navigation bar, tab bar, status bar, etc.
- Get link
- X
- Other Apps
Comments
Post a Comment