2014-03-13 47 views
1

我想构建一个使用2个容器视图嵌入UINavigationControllers的iPad的自定义拆分视图控制器...我设法做所有,但我有设置约束的问题,以便一切都很好地调整。使用容器视图构建自定义拆分视图

这是我到目前为止有: enter image description here

我不会要能够在某种程度上调整主视图(左容器),其详细视图(右容器)调整本身也消耗空间大师在自我调整的同时向左看。所以我想结束这样的:

enter image description here

其他尝试中我尝试添加这些约束:

主容器:顶父母,离开父母,底部的TabBar,高度,占位符宽度 当我从代码调整主容器的大小时,细节控制器始终停留在其原始位置。当我从代码调整主容器的大小时,细节控制器始终停留在其原始位置。

我试过100个场景,没有任何工作。

我做什么根本性的错误自动布局,但只是无法弄清楚什么..

这是调整大小代码:

-(void)ShowMaster:(BOOL)bShow animated:(BOOL)bAnimated 
    { 
     CGRect frame = masterViewContainer.frame; 

     if(bShow){ 
      frame.size.width = 280; 
     } 
     else{ 
      frame.size.width = 50; 
     } 

     masterViewContainer.frame = frame; 

    } 

任何形式的帮助将非常感激。

编辑: OK,我取得了一些进步,取代了我调整大小的代码与这一个:

-(void)ShowMaster:(BOOL)bShow animated:(BOOL)bAnimated 
{ 
    [UIView beginAnimations:@"" context:nil]; 
    if(bShow){ 
     [masterViewContainer addConstraint:[NSLayoutConstraint constraintWithItem:masterViewContainer 
                   attribute:NSLayoutAttributeWidth 
                   relatedBy:NSLayoutRelationEqual 
                   toItem:masterViewContainer 
                   attribute:NSLayoutAttributeWidth 
                  multiplier:0.5 
                   constant:280]]; 


    } 
    else{ 
     [masterViewContainer addConstraint:[NSLayoutConstraint constraintWithItem:masterViewContainer 
                   attribute:NSLayoutAttributeWidth 
                   relatedBy:NSLayoutRelationEqual 
                   toItem:masterViewContainer 
                   attribute:NSLayoutAttributeWidth 
                  multiplier:0.5 
                   constant:50]]; 

    } 
    [UIView commitAnimations]; 
} 

现在细节调整大小,但是当我尝试展开主,什么也没有发生......

回答

0

我解决了它。在我viewDidLoad中:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    if(masterWidthConstraint == nil){ 
     masterWidthConstraint = [NSLayoutConstraint constraintWithItem:masterViewContainer 
                  attribute:NSLayoutAttributeWidth 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:masterViewContainer 
                  attribute:NSLayoutAttributeWidth 
                  multiplier:0.0 
                   constant:280]; 


     [masterViewContainer addConstraint:masterWidthConstraint]; 
    } 


} 

在我ShowMaster方法我刚更新的约束和动画这样的:

-(void)ShowMaster:(BOOL)bShow animated:(BOOL)bAnimated 
{ 
    [UIView beginAnimations:@"" context:nil]; 

    if(bShow){ 
     masterWidthConstraint.constant = 280; 
    } 
    else{ 
     masterWidthConstraint.constant = 50; 
    } 

    [self.view setNeedsUpdateConstraints]; 
    [UIView animateWithDuration:0.9 animations:^{ 
     [self.view layoutIfNeeded]; 
    } completion:^(BOOL finished){}]; 
} 

在我的IB我设置占位符约束形式主视图宽度...而它的工作原理。唯一不能做的就是让IBOutlet达到IB宽度的限制,并且不知道为什么,但它的工作原理就像这样很好...

0

试试这个:

-(void)viewDidLayoutSubviews { 
    //your code 

} 
+0

不,它不起作用,但我想它谢谢,无论如何... – AntonijoDev