iOS 6 & iOS 7 Status Bar - objective-c

There are multiple questions about "switching from iOS 6 Status Bar to iOS 7", but I would like to ask the opposite.
My question is: How can I make iOS 6 screen frame slip under the status bar? I tried to move the self.window.frame and self.window.bounds in App Delegate, it is okay to shift up under the status bar, but the bottom will leave a 20 ~ 40px black line.
Here is the codes:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6 && [[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds = YES;
self.window.frame = CGRectMake(0, -20, self.window.frame.size.width, self.window.frame.size.height + 40);
self.window.bounds = CGRectMake(0, -40, self.window.frame.size.width, self.window.frame.size.height + 80);
}
I tried many values, but none fits my needs. What did I miss? I think I'm close.
Here is the mock screenshot I want to achieve ( I know the signal status of iOS 6 is not like this. Just to show the idea )
Note: only needs to support iOS 6+

My final solution is to remove the codes in App Delegate, and add IBOutlet to the header image of each page.
Then, in the method - (void)viewDidLayoutSubviews:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7")) {
[iv_header setFrame:CGRectMake(0, 0, 320, 60)];
}
where the if-case is defined as:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

Related

navigation bar overlapping with status bar on rotating device [duplicate]

This question already has answers here:
Status bar and navigation bar issue in IOS7
(11 answers)
Closed 8 years ago.
Hi status bar overlapping with navigation bar.though i am able to display correctly when i load screen when i rotate navigation bar and status bar overlaps i tried to set all these properties
if([[[UIDevice currentDevice] systemVersion]floatValue ] >= 7.0)
{
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
self.navigationController.navigationBar.translucent=NO;
self.edgesForExtendedLayout = UIRectEdgeAll;
}
If you're not using storyboard, then you can use this code in your AppDelegate.m in did finishlaunching:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}

iOS7,the statusbar is overlapping on my view when I setNavigationBarHidden to YES

In the ios7, the status bar is changed, it overlaps on my view.
I use this method to prevent this.
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
self.automaticallyAdjustsScrollViewInsets = NO;
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeNone;
}
It works when I have a navigationbar, but I set the navigationbar hidden, the problem comes again.
Add to your .plist file row:
View controller-based status bar appearance = NO

ios 7 status bar and navigation bar issue

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);
}

iphone 5 retina 4 inch mapview

I'm trying to adapt my app to retina 4 screen for iPhone 5, and adding the png archive and everything resizes but the map view, that moves to the top and leaves a white square on the bottom. I'd like to know how to fix it.
Thanks in advance.
Maybe this has to do with it?
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// We need to manually handle rotation on iPads running iOS 5 and higher to support the new UINavigationBar customization. This is automatic on the iPhone & iPod Touch.
if ([self.navigationController.navigationBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)] ) {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"UINavBarLandscape#iPad.png"] forBarMetrics:UIBarMetricsDefault];
}
else {
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"UINavBar#iPad.png"] forBarMetrics:UIBarMetricsDefault];
}
}
}
else {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[mapView setFrame:CGRectMake(0, 0, 480, 236)];
[toolbar setFrame:CGRectMake(0, 236, 480, 32)];
}
else {
[mapView setFrame:CGRectMake(0, 0, 320, 372)];
[toolbar setFrame:CGRectMake(0, 372, 320, 44)];
}
For the to top bar should be anchored to the top. the bottom bars anchored to the bottom of the controller's view. The map view should be anchored to the top and the bottom but should also have a vertical spring.
Now everything should expand correctly when you have a iphone 4 or 5.
Also if you are targeting iOS 6, take the time to use AutoLayout. That way when the iPhoneN has a different resolution you don't have to worry about the layout so much.
You have to check iPhone device version in your code programmatically and resize the controls accordingly.

Device orientation at launch

I've read ALL of the posts on this topic, but still can't figure this one out.
I add a VC to the window in applicationDidFinishLaunching. The VC contains a UIImageView.
I want to set the image of the UIImageView based on the device orientation, but statusBarOrientation, deviceOrientation, interfaceOrientation, everything I check returns portrait.
There's gotta be something simple I'm missing.
Your help is appreciated.
Have you enabled the other orientations in your Info.plist? There's a graphical editor for this in Xcode 4's project editor.
Sometimes (not sure if this is in every case, or just the simulator), the app will launch in one orientation and then immediately rotate to another orientation to match the device orientation.
I would suggest implementing -[UIViewController willRotateToInterfaceOrientation:duration:] to set your image, which should be called immediately after.
Well.. it seems there were several issues. 1) The simulator doesn't consistently generate orientation (or change in orientation) data as expected. Also, 2) immediately at start up, the device may (or may not) send statusBarOrientation info in time to read that. So, I did this right in the didFinishLaunching method in the app delegate.
// add the splash IV to the window per the current orientation, then animate it away
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait){
self.theSplashIV.image = [UIImage imageNamed:#"Default-Portrait~ipad.png"];
self.theSplashIV.frame = CGRectMake(0, 20, 768, 1004);
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown){
self.theSplashIV.image = [UIImage imageNamed:#"Default-Portrait~ipad.png"];
self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI);
self.theSplashIV.frame = CGRectMake(0, 0, 768, 1004);
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft){
self.theSplashIV.image = [UIImage imageNamed:#"Default-Landscape~ipad.png"];
self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI / 2);
self.theSplashIV.frame = CGRectMake(0, 0, 748, 1024);
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight){
self.theSplashIV.image = [UIImage imageNamed:#"Default-Landscape~ipad.png"];
self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI / -2);
self.theSplashIV.frame = CGRectMake(20, 0, 748, 1024);
}
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
And then I animate away the splash IV with a delay.
Not very elegant, but it works.