Auto Layout with navigation bar and view controller (iOS 7)

后端 未结 1 1051
我寻月下人不归
我寻月下人不归 2020-12-30 02:16

I\'m currently transiting my application to iOS 7 (I want it to remain iOS 6 compatible). This question is not covered by the Apple NDA, it is a question about Auto Layout (

相关标签:
1条回答
  • 2020-12-30 03:01

    On iOS 7 you have the topLayoutGuide that specify the navigation bar. You can then specify that you want that the constraint of the tableview is on the topLayoutGuide and not the superview.

    This will help you to know if it's iOS7 or not:

    if ([self respondsToSelector:@selector(topLayoutGuide)])
    

    So it can be something like that

    NSString *verticalConstraint = @"V:|[v]|";
    NSMutableDictionary *views = [NSMutableDictionary new];
    views[@"v"] = self.tableview;
    if ([self respondsToSelector:@selector(topLayoutGuide)]) {
        views[@"topLayoutGuide"] = self.topLayoutGuide;
        verticalConstraint = @"V:[topLayoutGuide][v]|";
    }
    [constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:verticalConstraint options:0 metrics:nil views:views]];
    [self.view addConstraints:constraints];
    
    0 讨论(0)
提交回复
热议问题