iOS7 - View under status bar - edgesForExtendedLayout not working

前端 未结 7 1885
予麋鹿
予麋鹿 2020-12-28 17:30

I have a project that was built last year, and it uses XIBs, no storyboards. The XIBs do not use Auto Layout, but they do use some Autosizing. I have an issue when running

相关标签:
7条回答
  • 2020-12-28 18:08

    Apple are pushing you to use autolayout to accomplish this. You need to set a constraint to the "Top Layout Guide" from the top subview in your view.

    See this document for examples:

    https://developer.apple.com/library/ios/qa/qa1797/_index.html

    To do this without XIBs, you'll need to add the constraint programatically. Apple's docs give a good example of this, which I've summarised below.

    Giving that the topLayoutGuide is a property on a view controller, you just use it in your dictionary of variable bindings. Then you set up your constraint like normal:

    id topGuide = [myViewController topLayoutGuide];
    NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(button, topGuide);
    NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[topGuide]-20-[button]" options:0 metrics:nil views:viewsDictionary]; 
    

    The documentation for this can be found in the UIViewController class reference.

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