Objective c iOS6中iOS7 LayoutGuide的替代品是什么

Objective c iOS6中iOS7 LayoutGuide的替代品是什么,objective-c,ios7,ios6,Objective C,Ios7,Ios6,我正在使用emccuntypickercontroller()进行应用程序开发中的国家/地区选择器。它在iOS7中运行良好。但它崩溃了,因为iOS6中没有LayoutGuide。我不知道如何将此代码更改为在iOS6中工作 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self validateSettings]; [se

我正在使用emccuntypickercontroller()进行应用程序开发中的国家/地区选择器。它在iOS7中运行良好。但它崩溃了,因为iOS6中没有LayoutGuide。我不知道如何将此代码更改为在iOS6中工作

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    [self validateSettings];
    [self loadCountries];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:searchBar
                                                         attribute:NSLayoutAttributeTop
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:self.topLayoutGuide
                                                         attribute:NSLayoutAttributeBottom
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:searchBar
                                                         attribute:NSLayoutAttributeCenterX
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:rootView
                                                         attribute:NSLayoutAttributeCenterX
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:searchBar
                                                         attribute:NSLayoutAttributeLeading
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:rootView
                                                         attribute:NSLayoutAttributeLeading
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:countryTable
                                                         attribute:NSLayoutAttributeTop
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:searchBar
                                                         attribute:NSLayoutAttributeBottom
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:rootView
                                                         attribute:NSLayoutAttributeTrailing
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:countryTable
                                                         attribute:NSLayoutAttributeTrailing
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:rootView
                                                         attribute:NSLayoutAttributeLeading
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:countryTable
                                                         attribute:NSLayoutAttributeLeading
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:self.bottomLayoutGuide
                                                         attribute:NSLayoutAttributeTop
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:countryTable
                                                         attribute:NSLayoutAttributeBottom
                                                        multiplier:1
                                                          constant:0]];

}

在将self.topLayoutGuide和self.bottomLayoutGuide替换为self.view后,它可以在iOS 6.1和7中工作


“此库是使用XCode 5.1.1构建的,使用iOS 7.1作为构建目标。此库要求iOS>=7。”您可能会发现下面还有其他问题。请检查此答案:
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:searchBar
                                                         attribute:NSLayoutAttributeTop
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:self.topLayoutGuide
                                                         attribute:NSLayoutAttributeBottom
                                                        multiplier:1
                                                          constant:0]];
    }else{
     [rootView addConstraint:[NSLayoutConstraint constraintWithItem:searchBar
                                                          attribute:NSLayoutAttributeTop
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeTop
                                                         multiplier:1
                                                           constant:0]];
    }
    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:searchBar
                                                         attribute:NSLayoutAttributeCenterX
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:rootView
                                                         attribute:NSLayoutAttributeCenterX
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:searchBar
                                                         attribute:NSLayoutAttributeLeading
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:rootView
                                                         attribute:NSLayoutAttributeLeading
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:countryTable
                                                         attribute:NSLayoutAttributeTop
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:searchBar
                                                         attribute:NSLayoutAttributeBottom
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:rootView
                                                         attribute:NSLayoutAttributeTrailing
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:countryTable
                                                         attribute:NSLayoutAttributeTrailing
                                                        multiplier:1
                                                          constant:0]];

    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:rootView
                                                         attribute:NSLayoutAttributeLeading
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:countryTable
                                                         attribute:NSLayoutAttributeLeading
                                                        multiplier:1
                                                          constant:0]];

    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:self.bottomLayoutGuide
                                                         attribute:NSLayoutAttributeTop
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:countryTable
                                                         attribute:NSLayoutAttributeBottom
                                                        multiplier:1
                                                          constant:0]];
    }else{
    [rootView addConstraint:[NSLayoutConstraint constraintWithItem:self.view
                                                         attribute:NSLayoutAttributeBottom
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:countryTable
                                                         attribute:NSLayoutAttributeBottom
                                                        multiplier:1
                                                          constant:0]];