My app's view is overlapped with status bar and navigationBar in ios7 device so I tried lots of solutions
uncheck 'under top bars' property in storyboard
self.edgesForExtendedLayout = UIRectEdgeNone;
set delta y to -20 in storyboard...
but none of these worked.
My last trial was adding these lines to appdelegate's didFinishLaunchingWithOptions
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
application.statusBarStyle = UIStatusBarStyleLightContent;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
self.window.clipsToBounds =YES;
} else {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
}
It works quite well when navigation bar is hidden but when nagivigation is not hidden,
navigationbar's frame is (0, 20, 320, 44) not (0, 0, 320, 44)
So navigationBar's height seems to be 64..
why is this? Hope someone explains me!
Thanks is advance :)
For a better explanation of the differences please see this transition guide (link).
Make sure you set this in viewWillAppear:
self.navigationController.navigationBar.translucent = NO;
self.edgesForExtendedLayout = UIRectEdgeNone;
To avoid the overlapping with the UINavigationBar, you must set its translucent property to NO.
As for the status bar, you have to manually set it by specifying its style and then reposition the whole window's frame. I would add on top of that an iOS 7 condition to make sure that only happen with users running iOS 7.
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height - 20);
}
Related
Sorry for Lengthy description-
On which Application I am working, it is 2 years old. As we wanted to give support for iOS 11. On particular view controller, we needed to rotate the screen with 180degree.
For this we used-
[[[UIApplication sharedApplication] delegate] window].transform = CGAffineTransformMakeRotation(M_PI);
By this way we actually transform the window.
It was working fine before iOS11.0. In iOS 11 when we again transform to original view then there is the problem with the status bar.
So, to resolving this issue I am changing the color of Navigation Bar as well as Status Bar,
#import "UINavigationController+Utilities.h"
#implementation UINavigationController (Utilities)
UIView *view;
-(void)setStatusBackground:(UIColor *)color
{
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"11.0"))
{
if (view == nil) {
view = [[UIView alloc] initWithFrame: CGRectMake(0, 0, DEVICE_SCREEN_WIDTH, 20)] ;
view.backgroundColor = color;
[self.view addSubview:view];
}
view.backgroundColor = color;
}
}
#end
Change background color of the navigation bar to Blue.
[self.navigationController.navigationBar setBarTintColor: HCCOLOR_BLUE];
[self.navigationController setStatusBackground:HCCOLOR_BLUE];
but the color is not same both. It looks little different.
I am adding the image-
This could be because might be your navigation bar is translucent
Try self.navigationController.navigationBar.translucent = NO;
Im working on a app compatible from ios6 onwards. in iOS 7 status bar is overlapping views and navigationbar. i want status bar in iOS 6 style. like it should appear above all UI objects, views,Viewcontroller and navigation controller. how can we achieve this?
For fixing the overlapping issue just try this link Status bar and navigation bar issue in IOS7
and for using status bar style similar to ios 6 this link may help you Change StatusBar style
In your app delegate's applicationDidFinishLaunching method:
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
Set UIStatusBarStyleBlackTranslucent/UIStatusBarStyleBlackOpaque for getting status bar similar to iOS6.
Hope this may help you
I am late for this Answer, but i just want to share what i did, which is basically
the easiest solution
First of all-> Go to your info.plist File and add Status Bar Style->Transparent Black Style(Alpha of 0.5)
Now ,here it Goes:-
Add this code in your AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Whatever your code goes here
if(kDeviceiPad){
//adding status bar for IOS7 ipad
if (IS_IOS7) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 1024, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
}
else{
//adding status bar for IOS7 iphone
if (IS_IOS7) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //You can give your own color pattern
[self.window.rootViewController.view addSubview:addStatusBar];
}
return YES;
}
In my navigation bar, I have a magnifying glass icon that brings up a search bar. I'm not using a UISearchDisplayController, so I opted to build my own UINavigationItem and then push it over the standard UINavigationItem using pushNavigationItem.
The problem is that the UINavigationItem seems to be pushed around 8 pixels to the right. This causes the cancel button (with localized text 'Annuleren') to be really close to the edge of the screen.
I tried inspecting the self.mySearchBar.bounds at runtime, but the origin is 0,0. I've played around a bit with AutoLayout and programmatically added constraints, but I haven't been successful. I hope it's possible without AutoLayout.
This is my code:
- (IBAction)displaySearchBar:(id)sender {
if (!self.mySearchNavigationItem)
{
self.mySearchNavigationItem = [[UINavigationItem alloc] initWithTitle:#""];
self.mySearchNavigationItem.hidesBackButton = YES;
self.mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
self.mySearchBar.showsCancelButton = YES;
self.mySearchBar.delegate = self;
[self.mySearchBar sizeToFit];
[self.mySearchBar setPlaceholder:#"Zoeken..."];
UIView *barWrapper = [[UIView alloc]initWithFrame:self.mySearchBar.bounds];
[barWrapper addSubview:self.mySearchBar];
self.mySearchNavigationItem.leftBarButtonItem = nil;
self.mySearchNavigationItem.backBarButtonItem = nil;
self.mySearchNavigationItem.titleView = barWrapper;
UIButton *cancelButton;
UIView *topView = self.mySearchBar.subviews[0];
for (UIView *subView in topView.subviews) {
if ([subView isKindOfClass:NSClassFromString(#"UINavigationButton")]) {
cancelButton = (UIButton*)subView;
}
}
if (cancelButton) {
[cancelButton setTitle:#"Annuleren" forState:UIControlStateNormal];
}
}
[self.navigationController.navigationBar pushNavigationItem:self.mySearchNavigationItem animated:YES];
NSTimeInterval delay;
if (self.tableView.contentOffset.y >1000) delay = 0.4;
else delay = 0.1;
[self performSelector:#selector(activateSearch) withObject:nil afterDelay:delay];
}
try:
self.navigationController.navigationBar.barTintColor = self.mySearchBar.barTintColor;
if that doesn't work, you can add an underlay view to the navigation controller that is the color you would like. this may be useful: Get the right color in iOS7 translucent navigation bar
After searching for many hours, I gave up and went for a dirty fix. I'll leave it open for a while, in case someone knows why my searchbar is moved 8 pixels to the right.
Right before showing the UINavigationItem, I move the whole UINavigationBar to x-coordinate -8.
self.navigationController.navigationBar.frame = CGRectMake(-8.0, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
[self.navigationController.navigationBar pushNavigationItem:self.mySearchNavigationItem animated:YES];
And then on the cancel button click, I move it back to x-coordinate 0.
- (IBAction)cancelSearchBar:(id)sender {
[self.navigationController.navigationBar popNavigationItemAnimated:YES];
self.navigationController.navigationBar.frame = CGRectMake(0.0, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
}
I have a UITabBarController with two UITableViews, all were created in the storyboard.
The problem is that in the second tableview the first few lines of the table are under the top bar, this doesn't happens with the first tableview, even if I change the order of the views the first will work perfectly and the second will present the problem, so the one that was working perfectly now presents the same problem because is the second item of the tabbar controller.
I don't have much code to show because I didn't create the tableviews programatically.
Not sure exactly based on your description, but a couple possibilities come to mind:
Check your view controller attributes inspector in IB. Look for
"Extend Edges" option under View Controller, and uncheck "Under Top
Bars" if it is checked.
In ios7, there appears to be a behavior in UIScrollView and all
subclasses whereby the content inset and offset is automatically adjusted, sometimes not very well. You
can try disabling that either in code or IB (see link for
how: iOS 7 -- navigationController is setting the contentInset and ContentOffset of my UIScrollView)
For any newly created iOS >7.0 app I suggest you take a deeper look at autolayout. For all my old iOS 6 apps I solved it like this:
In your UITableViewController interface:
bool _hasStatusBar;
bool _hasStatusBarHeight;
UIView *_blendView;
In your UITableViewController implementation file:
-(void)viewWillAppear:(BOOL)animated{
_hasStatusBar = NO;
_blendView = nil;
[self.tableView reloadData];
}
-(void)viewWillDisappear:(BOOL)animated{
_hasStatusBar = NO;
_blendView = nil;
}
- (void) viewDidLayoutSubviews {
// WTF APPLE!?
if (!_hasStatusBar) {
int topBarOffset = 20;
_hasStatusBar = YES;
// Fix for iOS 7 overlaying status bar
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect viewBounds = self.view.bounds;
_blendView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewBounds.size.width, topBarOffset)];
[_blendView setBackgroundColor:COLOR_MAIN];
[_blendView setOpaque:YES];
[_blendView setAlpha:1.00];
UIView *whityMacWhite = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewBounds.size.width, topBarOffset)];
[whityMacWhite setBackgroundColor:[UIColor whiteColor]];
[whityMacWhite setOpaque:NO];
[whityMacWhite setAlpha:0.80];
[_blendView addSubview:whityMacWhite];
[self.view.superview addSubview:_blendView];
}
}
}
After lot of googling i am asking this question. I have an app, i want to make it compatible with the iPhone5. I added Default-568h#2x to my app which contains nearly 10views. So I changed views like this..
In viewDidLoad:
if ([[UIScreen mainScreen] bounds].size.height >= 568) {
self.view.frame = CGRectMake(0, 0, 320, 568);
//iPhone5
}
else {
}
window.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
I have made this change in my didFinishLaunching with options:
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
After doing like this I found Some issues..
The bottom of the screen i.e 88px long is not touchable even the controls placed on it - for this i have set FullScreenAtLaunch checked in attributes of MainWindow.xib, but doesn`t worked
I have textbox on view, when it is focussed keyboard is coming but on top of the Keyboard view coming, how to get rid of that.
How to resolve this, any help would be greatly appreciated.
Thanks
This because in the line where you create your UIWindow in the App delegate class you will probably have something like this:
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,480);
change it to something like:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
also where you now do:
if ([[UIScreen mainScreen] bounds].size.height >= 568) {
self.view.frame = CGRectMake(0, 0, 320, 568);
//iPhone5
}
else {
}
You coud as well do:
self.view.frame = [[UIScreen mainScreen] bounds];
But most of the time this ins't needed since the view of the viewcontroller will take op the space correctly. If you have set the AutoResizeMasks in interface builder correctly you will not gave to set the frame in code.