matt saravitz
matt saravitz

Reputation: 157

Auto Adjust Storyboard Webview size according to navigation bar

I have a webview in a viewcontroller with a navigation bar and a toolbar. I have a hide toolbar and nav bar button, but when they hide the size of the webview doesn't adjust to fit the screen. I used this code:

-(IBAction)hide:(id)sender {
myView.frame = CGRectMake(0,0,320,480);
[[[self navigationController] navigationBar]  setHidden:YES];
[[[self navigationController] toolbar] setHidden:YES];
   [self.view addSubview:myView];
 }

 -(BOOL)canBecomeFirstResponder {

return YES;

 }

 -(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {

if (event.subtype == UIEventSubtypeMotionShake) {

    myView.frame = CGRectMake(0,0,320,382);
    [[[self navigationController] navigationBar]  setHidden:NO];
    [[[self navigationController] toolbar] setHidden:NO];
    [self.view addSubview:myView];

}

 }

They hide properly but how can i adjust the size properly? Im using storyboard btw.

Upvotes: 1

Views: 656

Answers (1)

Alex
Alex

Reputation: 8991

What is myView?

Try setting the following on the instance of the UIViewView in -(void)viewDidLoad or via Interface Builder/Storyboard:

webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

By setting the autoresizing mask as shown, when the view's superview changes its bounds the webview will grow and shrink with it.

Upvotes: 1

Related Questions