2
votes

I have a custom UIViewController which create a view containing an action bar at the top (view with 4 buttons), a tableview and then another view below the tableview. Layout is done all in code and is not using auto layout. Everything works perfectly on various device with iOS 7.0 and 7.0.2, but in the simulator, the root view of the controller get anchored at the top right corner of the screen (0,0) instead of below the navigation bar.

I'm going to force the relay out in the viewDidAppear: method, but this seem like a hack...

Thanks for any insights

enter image description here Edit: added an image. You can see the UIView highlighted. As ManicMonkOnMac mentioned, the UIView is under the toolbar (but this only happens in the simulator, on the device, the view lines up fine) In the loadView method on the controller, i set the frame when creating the view:

- (void)loadView
{
    // Our parent view controller will resize us appropriately. The size set
    // here is a convenience for initial view layout.
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

But this frame is later changed. Not by my code, though, but by UIkit code)

Edit2: addded loadView method body

1
screenshot will be better to understand this problemCintu

1 Answers

3
votes

EDIT: After going through session 201 of WWDC 2013, I think I have the solution.

in iOS 7 there is a property that you can set on your view controllers to specify whether you want the views to be overlapped by navigation bar.

viewController.edgesForExtendedLayout = UIRectEdgeNone;//UIRectEdgeAll specifies that nav bars should overlap the view.

Unlike iOS 6, navigation bars are placed over the views in iOS 7.

Use the frame size that excludes the navigation bar.

code:

CGRect frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y+self.navigationController.navigationBar.frame.size.height,self.view.frame.size.width,self.view.frame.size.height);

CustomView *view = [[CustomView alloc] initWithFrame:frame];

[self.view addSubview: view];