CB-5595 Fixed the positioning and autoresizing for certain rotation scenarios.

The autoresizing masks are applied conditonally based on the
browserOptions.toolbarposition flag to ensure that the toolbar is in
its correct place. Also added a utility function to query the
necessary offset for the status bar: the function takes care of the iOS
version and orientation caused differences without hardcoding the value
as 20 pixels.
This commit is contained in:
Peter Somogyvari 2013-11-18 17:14:19 +00:00 committed by Andrew Grieve
parent 20611efe67
commit 4aeaf81e1e

View File

@ -463,7 +463,7 @@
self.toolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame]; self.toolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];
self.toolbar.alpha = 1.000; self.toolbar.alpha = 1.000;
self.toolbar.autoresizesSubviews = YES; self.toolbar.autoresizesSubviews = YES;
self.toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; self.toolbar.autoresizingMask = toolbarIsAtBottom ? (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin) : UIViewAutoresizingFlexibleWidth;
self.toolbar.barStyle = UIBarStyleBlackOpaque; self.toolbar.barStyle = UIBarStyleBlackOpaque;
self.toolbar.clearsContextBeforeDrawing = NO; self.toolbar.clearsContextBeforeDrawing = NO;
self.toolbar.clipsToBounds = NO; self.toolbar.clipsToBounds = NO;
@ -719,12 +719,21 @@
[super viewWillAppear:animated]; [super viewWillAppear:animated];
} }
//
// On iOS 7 the status bar is part of the view's dimensions, therefore it's height has to be taken into account.
// The height of it could be hardcoded as 20 pixels, but that would assume that the upcoming releases of iOS won't
// change that value.
//
- (float) getStatusBarOffset {
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
float statusBarOffset = IsAtLeastiOSVersion(@"7.0") ? MIN(statusBarFrame.size.width, statusBarFrame.size.height) : 0.0;
return statusBarOffset;
}
- (void) rePositionViews { - (void) rePositionViews {
if ([_browserOptions.toolbarbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop]) { if ([_browserOptions.toolbarbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop]) {
[self.webView setFrame:CGRectMake(self.webView.frame.origin.x, TOOLBAR_HEIGHT, self.webView.frame.size.width, self.webView.frame.size.height)]; [self.webView setFrame:CGRectMake(self.webView.frame.origin.x, TOOLBAR_HEIGHT, self.webView.frame.size.width, self.webView.frame.size.height)];
[self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, [self getStatusBarOffset], self.toolbar.frame.size.width, self.toolbar.frame.size.height)];
float offsetForStatusBar = IsAtLeastiOSVersion(@"7.0") ? 21.0 : 0.0;
[self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, self.toolbar.frame.origin.y + offsetForStatusBar, self.toolbar.frame.size.width, self.toolbar.frame.size.height)];
} }
} }