Reputation: 1061
In order to fix the overlapping of status bar and navigation bar in iOS 7+, i'm using this code inside didFinishLaunchingWithOptions
in AppDelegate.m
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//some codes
//.
//.
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
UIView *FakeNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
FakeNavBar.backgroundColor = UIColorFromRGB(0x55BCAFF);
float navBarHeight = 20.0;
for (UIView *subView in self.window.subviews) {
if ([subView isKindOfClass:[UIScrollView class]]) {
subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height - navBarHeight);
} else {
subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height);
}
}
[self.window addSubview:FakeNavBar];
}
}
It pushes all my controllers and views 20 pixels down and and the overlapping problem gets fixed but when i reach my tab view controller scene, then the tab bar on the bottom goes out of view by 20 pixels.
So how can i keep the tab bar in its place while shifting everything else down?
It would also work if i could just shift up only the tab bar by 20 pixels.
Upvotes: 1
Views: 125
Reputation: 1131
I assume that you're not using a navigation controller and you've manually added the navigation bar in your view. Is that right?
You should be able to achieve what you're after by adding a view with a size of the status bar at the top of the views of your view controllers in the storyboard.
Are you using auto-layout constraints? You could use them to make these views stick to the top of your views, have a fixed height of 20 pixels and a width equal to the width of the view controller's view.
Upvotes: 0
Reputation: 1061
I was able to shift only the tab bar 20 pixels up but this may put some views behind the tab bar which is unwanted.
here is the code written inside viewDidAppear
of my UITabBarController class :
-(void)viewDidAppear:(BOOL)animated{
CGRect newFrame = self.tabBar.frame;
newFrame.origin.y -= 20;
self.tabBar.frame = newFrame;
}
Upvotes: 1
Reputation: 2654
Please use the code below -
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
UIView *FakeNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
FakeNavBar.backgroundColor = UIColorFromRGB(0x55BCAFF);
float navBarHeight = 20.0;
for (UIView *subView in self.window.subviews) {
for (int index=0; index<[tabBarController.viewControllers count]; index++)
{
if ([subView isKindOfClass:[[(UIViewController*)[tabBarController.viewControllers objectAtIndex:index] view] class]])
{
continue;
}
}
if ([subView isKindOfClass:[UIScrollView class]]) {
subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height - navBarHeight);
} else {
subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y + navBarHeight, subView.frame.size.width, subView.frame.size.height);
}
}
[self.window addSubview:FakeNavBar];
}
Upvotes: 0