Is there any way to add constraint between a view and the top layout guide in a xib file?

后端 未结 7 2319
时光说笑
时光说笑 2020-12-07 15:44

In iOS 7, we can now add a constraint between a view and the top layout guide, which I think is very useful to solve the status bar offset issue in iOS7(especially when ther

相关标签:
7条回答
  • 2020-12-07 16:16

    Here is my alternative solution.

    Find a UIView as a pivot, set its top layout constraint a fixed vertical space to container's top.

    Control-Drag this layout constraint as an IBOutlet, such as

    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLayoutConstraint;
    

    Finally, just override viewWillLayoutSubviews method of UIViewController like following

    - (void)viewWillLayoutSubviews
    {
        [super viewWillLayoutSubviews];
    
        self.topLayoutConstraint.constant = [self.topLayoutGuide length] + YOUR_TOP_CONSTRSINT;
    }
    

    All the other views' top constraint are based this pivot view, all done :)

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