The Immi's answer is good. But for those, who has iPad problem:
You should make the width correct, so replace the:
UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0., 0., 320., 63.)];
with this
UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0., 0., [[UIScreen mainScreen] bounds].size.width, 63.)];
Also the Google title is hidden by navigation Bar. Not good. So do the next:
In
- (void)moveWebViewFromUnderNavigationBar
change
CGRect webFrame = CGRectMake(0., 63., self.view.frame.size.width, self.view.frame.size.height);
and in
- (void)viewWillAppear:(BOOL)animated
comment out calling of method [self isNavigationBarTranslucent]
:
// if ([self isNavigationBarTranslucent]) {
[self moveWebViewFromUnderNavigationBar];
// }
UPD. for interface orientation
To make the navBar change due to interface orientation, I recommend to use NSNotification Center, see this answer.
As for this situation, you should do the next:
- Implement your NavBar in @interface in GTMOAuth2ViewControllerTouch.m
- Put the notification listener in ViewDidLoad.
- Make the navBar change.
So, let's go:
right under @interface
put
@property (nonatomic, strong) UINavigationBar *naviBarObj;
in ViewDidLoad:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(deviceOrientationDidChangeNotification:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
and finally:
-(void)deviceOrientationDidChangeNotification:(NSNotification*)note
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown)
{
self.naviBarObj.frame = CGRectMake(0., 0., [[UIScreen mainScreen] bounds].size.width, 63.0);
}
else if (orientation == UIDeviceOrientationLandscapeRight || orientation == UIDeviceOrientationLandscapeLeft)
{
self.naviBarObj.frame = CGRectMake(0., 0., [[UIScreen mainScreen] bounds].size.height, 63.0);
} }
P.S. don't forget, that you should now use self.naviBarObj
everywhere you used naviBarObj
. And remove the UINavigationBar
before naviBarObj
in ViewDidLoad
UPD 2.0
- (CGRect) setNavBarWidth
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown)
{
return CGRectMake(0., 0., [[UIScreen mainScreen] bounds].size.width, 63.0);
}
else if (orientation == UIDeviceOrientationLandscapeRight || orientation == UIDeviceOrientationLandscapeLeft)
{
return CGRectMake(0., 0., [[UIScreen mainScreen] bounds].size.height, 63.0);
}
return CGRectMake(0., 0., [[UIScreen mainScreen] bounds].size.width, 63.0);
}
And call it self.naviBarObj = [[UINavigationBar alloc] initWithFrame:[self setNavBarWidth]];
from viewDidLoad
, as well as
self.naviBarObj.frame = [self setNavBarWidth];
from deviceOrientationDidChangeNotification
methods then :)