Not sure why UIView is being nudged up by around 10px

后端 未结 5 842
萌比男神i
萌比男神i 2020-12-09 12:10

I\'ve created a simple iPhone app which has two .xib files. In the app delegate at application did finish launching I display the first .xib file by calling:



        
相关标签:
5条回答
  • 2020-12-09 12:53

    When using a UIViewController the normal way (i.e. pushing it on a UINavigationController), it adjusts its view's frame.

    Since you're adding the subview manually, you have to adjust the frame yourself. The origin is in the upper right corner (at the top of the status bar). You want to shift your view 20 pixels down.

    0 讨论(0)
  • 2020-12-09 12:58

    Whenever a weird gap appears, or the view is partly hidden behind the status bar, it has something to do with either

    1. shouldAutorotate definition in your root controller - not sure if it is a bug or not, but try to stay consistent with the return of that function for all sub-viewcontrollers (usually results in a viewcontroller being hidden behind the status bar)
    2. a wantsFullscreen definition of a subview - set to NO if possible

    i had both bugs in my app and solved them! Hope I could save you some time (I wasted a lot on it)

    0 讨论(0)
  • 2020-12-09 13:07

    Looks like you call pushVC to this UIViewController in the wrong place. I had the same problem. It was solved by moving [self.navigationController pushViewController: animated:] from viewDidLoad to viewDidAppear: in a previous UIViewController in hierarchy.

    0 讨论(0)
  • 2020-12-09 13:08

    Here is my solution:

    // adjust the frame of subview which is going to be add
    self.navController.view.frame = CGRectMake(0, 0, 320, 460);
    [self.view addSubView:self.navController.view];
    

    It works fine for me now, good luck~ :)

    0 讨论(0)
  • 2020-12-09 13:08

    In interface builder, you can add Simulated Interface Elements that will appear programatically (such as the status bar or the navigation bar). In your inspector, select your view, and go to the Attributes tab. Here you can simulate The Status bar, a top bar, or a bottom bar.

    0 讨论(0)
提交回复
热议问题