Permalink
Browse files

Fixed more weird toolbar glitches when in landscape mode and presente…

…d modally.
  • Loading branch information...
1 parent bdd8d5a commit 55dfe96af5d1cbb11e21e70d76a8e909573df23f @samvermette samvermette committed Jun 30, 2011
Showing with 16 additions and 8 deletions.
  1. +16 −8 SVWebViewController/SVWebViewController.m
View
24 SVWebViewController/SVWebViewController.m
@@ -58,22 +58,18 @@ - (void)viewDidLoad {
forwardBarButton.width = 18;
actionBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showActions)];
-
+
if(self.navigationController == nil) {
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0,CGRectGetWidth(deviceBounds),44)];
- navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin;
+ navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:navBar];
[navBar release];
navItem = [[UINavigationItem alloc] initWithTitle:self.title];
[navBar setItems:[NSArray arrayWithObject:navItem] animated:YES];
[navItem release];
- UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissController)];
- navItem.leftBarButtonItem = doneButton;
- [doneButton release];
-
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view.bounds)-44, CGRectGetWidth(deviceBounds), 44)];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleWidth;
[self.view addSubview:toolbar];
@@ -241,10 +237,13 @@ - (void)viewDidDisappear:(BOOL)animated {
- (void)layoutSubviews {
CGRect deviceBounds = self.view.bounds;
- if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation) && !deviceIsTablet && !self.navigationController)
+ if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation) && !deviceIsTablet && !self.navigationController) {
navBar.frame = CGRectMake(0, 0, CGRectGetWidth(deviceBounds), 32);
- else if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation) && !deviceIsTablet && !self.navigationController)
+ toolbar.frame = CGRectMake(0, CGRectGetHeight(deviceBounds)-32, CGRectGetWidth(deviceBounds), 32);
+ } else if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation) && !deviceIsTablet && !self.navigationController) {
navBar.frame = CGRectMake(0, 0, CGRectGetWidth(deviceBounds), 44);
+ toolbar.frame = CGRectMake(0, CGRectGetHeight(deviceBounds)-44, CGRectGetWidth(deviceBounds), 44);
+ }
if(self.navigationController && deviceIsTablet)
self.webView.frame = CGRectMake(0, 0, CGRectGetWidth(deviceBounds), CGRectGetHeight(deviceBounds));
@@ -265,6 +264,12 @@ - (void)layoutSubviews {
- (void)setupToolbar {
+ if(!navItem.leftBarButtonItem) {
+ UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissController)];
+ [navItem setLeftBarButtonItem:doneButton animated:YES];
+ [doneButton release];
+ }
+
if(self.navigationController != nil)
self.navigationItem.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
else
@@ -300,6 +305,9 @@ - (void)setupToolbar {
NSArray *newButtons = [NSArray arrayWithObjects:fixedSpace, backBarButton, flexSpace, forwardBarButton, flexSpace, refreshStopBarButton, flexSpace, actionBarButton, fixedSpace, nil];
[toolbar setItems:newButtons];
+ [toolbar sizeToFit];
+
+ NSLog(@"toolbar frame is %@", NSStringFromCGRect(toolbar.frame));
[refreshStopBarButton release];
[flexSpace release];

0 comments on commit 55dfe96

Please sign in to comment.