@@ -35,7 +35,6 @@ Licensed to the Apache Software Foundation (ASF) under one
35
35
#define IAB_BRIDGE_NAME @" cordova_iab"
36
36
37
37
#define TOOLBAR_HEIGHT 44.0
38
- #define STATUSBAR_HEIGHT 20.0
39
38
#define LOCATIONBAR_HEIGHT 21.0
40
39
#define FOOTER_HEIGHT ((TOOLBAR_HEIGHT) + (LOCATIONBAR_HEIGHT))
41
40
@@ -698,7 +697,7 @@ @implementation CDVWKInAppBrowserViewController
698
697
699
698
@synthesize currentURL;
700
699
701
- BOOL viewRenderedAtLeastOnce = FALSE ;
700
+ CGFloat lastReducedStatusBarHeight = 0.0 ;
702
701
BOOL isExiting = FALSE ;
703
702
704
703
- (id )initWithBrowserOptions : (CDVInAppBrowserOptions*) browserOptions andSettings : (NSDictionary *)settings
@@ -896,7 +895,7 @@ - (void)createViews
896
895
[self .toolbar setItems: @[self .closeButton, flexibleSpaceButton, self .backButton, fixedSpaceButton, self .forwardButton]];
897
896
}
898
897
899
- self.view .backgroundColor = [UIColor grayColor ];
898
+ self.view .backgroundColor = [UIColor clearColor ];
900
899
[self .view addSubview: self .toolbar];
901
900
[self .view addSubview: self .addressLabel];
902
901
[self .view addSubview: self .spinner];
@@ -1042,7 +1041,6 @@ - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition
1042
1041
1043
1042
- (void )viewDidLoad
1044
1043
{
1045
- viewRenderedAtLeastOnce = FALSE ;
1046
1044
[super viewDidLoad ];
1047
1045
}
1048
1046
@@ -1103,14 +1101,6 @@ - (void)goForward:(id)sender
1103
1101
1104
1102
- (void )viewWillAppear : (BOOL )animated
1105
1103
{
1106
- if (IsAtLeastiOSVersion (@" 7.0" ) && !viewRenderedAtLeastOnce) {
1107
- viewRenderedAtLeastOnce = TRUE ;
1108
- CGRect viewBounds = [self .webView bounds ];
1109
- viewBounds.origin .y = STATUSBAR_HEIGHT;
1110
- viewBounds.size .height = viewBounds.size .height - STATUSBAR_HEIGHT;
1111
- self.webView .frame = viewBounds;
1112
- [[UIApplication sharedApplication ] setStatusBarStyle: [self preferredStatusBarStyle ]];
1113
- }
1114
1104
[self rePositionViews ];
1115
1105
1116
1106
[super viewWillAppear: animated];
@@ -1122,16 +1112,28 @@ - (void)viewWillAppear:(BOOL)animated
1122
1112
// change that value.
1123
1113
//
1124
1114
- (float ) getStatusBarOffset {
1125
- CGRect statusBarFrame = [[UIApplication sharedApplication ] statusBarFrame ];
1126
- float statusBarOffset = IsAtLeastiOSVersion (@" 7.0" ) ? MIN (statusBarFrame.size .width , statusBarFrame.size .height ) : 0.0 ;
1127
- return statusBarOffset;
1115
+ return (float ) IsAtLeastiOSVersion (@" 7.0" ) ? [[UIApplication sharedApplication ] statusBarFrame ].size .height : 0.0 ;
1128
1116
}
1129
1117
1130
1118
- (void ) rePositionViews {
1131
- if ([_browserOptions.toolbarposition isEqualToString: kInAppBrowserToolbarBarPositionTop ]) {
1132
- [self .webView setFrame: CGRectMake (self .webView.frame.origin.x, TOOLBAR_HEIGHT, self .webView.frame.size.width, self .webView.frame.size.height)];
1133
- [self .toolbar setFrame: CGRectMake (self .toolbar.frame.origin.x, [self getStatusBarOffset ], self .toolbar.frame.size.width, self .toolbar.frame.size.height)];
1119
+ CGRect viewBounds = [self .webView bounds ];
1120
+ CGFloat statusBarHeight = [self getStatusBarOffset ];
1121
+
1122
+ // orientation portrait or portraitUpsideDown: status bar is on the top and web view is to be aligned to the bottom of the status bar
1123
+ // orientation landscapeLeft or landscapeRight: status bar height is 0 in but lets account for it in case things ever change in the future
1124
+ viewBounds.origin .y = statusBarHeight;
1125
+
1126
+ // account for web view height portion that may have been reduced by a previous call to this method
1127
+ viewBounds.size .height = viewBounds.size .height - statusBarHeight + lastReducedStatusBarHeight;
1128
+ lastReducedStatusBarHeight = statusBarHeight;
1129
+
1130
+ if ((_browserOptions.toolbar ) && ([_browserOptions.toolbarposition isEqualToString: kInAppBrowserToolbarBarPositionTop ])) {
1131
+ // if we have to display the toolbar on top of the web view, we need to account for its height
1132
+ viewBounds.origin .y += TOOLBAR_HEIGHT;
1133
+ self.toolbar .frame = CGRectMake (self.toolbar .frame .origin .x , statusBarHeight, self.toolbar .frame .size .width , self.toolbar .frame .size .height );
1134
1134
}
1135
+
1136
+ self.webView .frame = viewBounds;
1135
1137
}
1136
1138
1137
1139
// Helper function to convert hex color string to UIColor
@@ -1242,4 +1244,27 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations
1242
1244
return 1 << UIInterfaceOrientationPortrait;
1243
1245
}
1244
1246
1247
+ - (BOOL )shouldAutorotateToInterfaceOrientation : (UIInterfaceOrientation)interfaceOrientation
1248
+ {
1249
+ if ((self.orientationDelegate != nil ) && [self .orientationDelegate respondsToSelector: @selector (shouldAutorotateToInterfaceOrientation: )]) {
1250
+ return [self .orientationDelegate shouldAutorotateToInterfaceOrientation: interfaceOrientation];
1251
+ }
1252
+
1253
+ return YES ;
1254
+ }
1255
+
1256
+ - (void )viewWillTransitionToSize : (CGSize)size withTransitionCoordinator : (id <UIViewControllerTransitionCoordinator>)coordinator
1257
+ {
1258
+ [coordinator animateAlongsideTransition: ^(id <UIViewControllerTransitionCoordinatorContext> context)
1259
+ {
1260
+ [self rePositionViews ];
1261
+ } completion: ^(id <UIViewControllerTransitionCoordinatorContext> context)
1262
+ {
1263
+
1264
+ }];
1265
+
1266
+ [super viewWillTransitionToSize: size withTransitionCoordinator: coordinator];
1267
+ }
1268
+
1269
+
1245
1270
@end // CDVWKInAppBrowserViewController
0 commit comments