0

I have created two ViewCrontroller using xib and set orientation of UIViews is LandscapeLeft.

and than add this code to

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

enter image description here

The following is my ideal result:

  1. I'd like the window under the status bar in ios 7,

  2. The first view, the result is what I want to get, however, when it jumps to the second view, there is a problem! The window move 20px to the left. how to fit it into the normal view?

3.Most impornatant condition is Autolayout is "TRUE".

my testing code: https://www.dropbox.com/s/bj9wg4hwar1t8y0/statusbartesting.zip

Can anyone help to solve this problem?

enter image description here

enter image description here

bvsss
  • 72
  • 6
nang531
  • 65
  • 6
  • You should not change the frame of the window but the frame of the underlying view! Be aware that, since iOS7 we do have the edgesForExtendedLayout property on every view controller to handle this behaviour. Further, in storyboards, you could unselect 'Extend Edges - Under Top Bars' etc. to get what you want – Alexander Jun 23 '14 at 06:36
  • @Alexander,i add this code to my project,but not work! if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){ self.edgesForExtendedLayout = UIRectEdgeNone; self.extendedLayoutIncludesOpaqueBars = NO; } – nang531 Jun 23 '14 at 07:10
  • Are you using an navigation controller as container? If not I would suggest to do so (you can hide the bar) see http://stackoverflow.com/questions/18912290/how-to-present-a-view-controller-on-ios7-without-the-status-bar-overlapping – Alexander Jun 23 '14 at 07:51
  • @Alexander,thanks for your help!i have not using an navigation controller and i want to show the status bar,I solve this problem in storyboard,but it is not work using xib. – nang531 Jun 23 '14 at 08:54

1 Answers1

0

You don't need to change window frame in AppDelegate.

I'll tell you code, please follow it

Appdelegate.m

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        self.mxfirstciewcontroller = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];

        self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.mxfirstciewcontroller];
        [(UINavigationController *)self.window.rootViewController setNavigationBarHidden:YES];

        return YES;
    }

In firstViewController.m

- (void)viewDidAppear:(BOOL)animated
{

    [super viewDidAppear:animated];
    [self.view setFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height)];
}

In secondViewController.m

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    [self.view setFrame:CGRectMake(20, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76
Rohit
  • 577
  • 1
  • 3
  • 13
  • @LorD Zsolt,@Rohit why the views have different orientation? do you have a global solution,maybe set something for the window ,do not set to every viewcontroller! – nang531 Jun 23 '14 at 06:49
  • follow this link it would be help you http://stackoverflow.com/questions/9539676/uiviewcontroller-returns-invalid-frame – Rohit Jun 23 '14 at 11:32