小编Dhi*_*Yes的帖子

如何在父视图上添加子视图控制器的视图

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    ChildViewController *childviewcontroller = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];


    [self addChildViewController:childviewcontroller];
    [self.view addSubview:childviewcontroller.view];
    [childviewcontroller willMoveToParentViewController:self];
    UIView *cview = [[UIView alloc] init];
    cview = childviewcontroller.view;
    [self.view removeConstraints:self.view.constraints];

    NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(cview);
    [self.view addConstraints:[NSLayoutConstraint 
                                constraintsWithVisualFormat:@"H:|-[cview]-|" 
                                                    options:0 metrics:nil                                        
                                                    views:viewsDictionary]];

}
Run Code Online (Sandbox Code Playgroud)

我想在父视图上添加childviewcontroller视图.添加后我设置了约束,但它对我不起作用.

我也收到这样的警告

2013-07-25 10:47:30.564 neenah[1105:c07] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try …
Run Code Online (Sandbox Code Playgroud)

ios autolayout nsautolayout

7
推荐指数
1
解决办法
4243
查看次数

标签 统计

autolayout ×1

ios ×1

nsautolayout ×1