2013-07-20 35 views
1

在我的应用程序,我有以下设置:Autolayout:添加视图打破我的工作调整大小 - 想法?

的TextView(self.textView)

工具栏

当键盘变得可见,我添加了一个约束条件将文本视图的底部向上推动所需的像素数。

spacer =[NSLayoutConstraint 
            constraintWithItem:self.textView 
            attribute:NSLayoutAttributeBottom 
            relatedBy:NSLayoutRelationEqual 
            toItem:self.view 
            attribute:NSLayoutAttributeBottom 
            multiplier:1.0 
            constant:-height]; 
[self.view addConstraint:spacer]; 

当键盘消失时,我删除约束。

这工作很好。然而...

我想添加一个位于文本视图顶部的imageview。这似乎很简单。但是现在“解雇键盘”的大小被打破了。

下面是我用来创建imageview并将其固定到textview界限的代码。

self.overlay = [[UIImageView alloc] init]; 

[self.overlay setTranslatesAutoresizingMaskIntoConstraints:NO]; 
[self.view addSubview:self.overlay]; 

[self.view addConstraint: [NSLayoutConstraint 
          constraintWithItem:self.overlay 
          attribute:NSLayoutAttributeBottom 
          relatedBy:NSLayoutRelationEqual 
          toItem:self.textView 
          attribute:NSLayoutAttributeBottom 
          multiplier:1.0 
          constant:0]]; 
[self.view addConstraint: [NSLayoutConstraint 
          constraintWithItem:self.overlay 
          attribute:NSLayoutAttributeTop 
          relatedBy:NSLayoutRelationEqual 
          toItem:self.textView 
          attribute:NSLayoutAttributeTop 
          multiplier:1.0 
          constant:0]]; 
[self.view addConstraint: [NSLayoutConstraint 
          constraintWithItem:self.overlay 
          attribute:NSLayoutAttributeLeft 
          relatedBy:NSLayoutRelationEqual 
          toItem:self.textView 
          attribute:NSLayoutAttributeLeft 
          multiplier:1.0 
          constant:0]]; 
[self.view addConstraint: [NSLayoutConstraint 
          constraintWithItem:self.overlay 
          attribute:NSLayoutAttributeRight 
          relatedBy:NSLayoutRelationEqual 
          toItem:self.textView 
          attribute:NSLayoutAttributeRight 
          multiplier:1.0 
          constant:0]]; 
[self.view layoutIfNeeded]; 

下面是它应该是什么样子:键盘前

初步显示

Initial before keyboard showing

键盘显示

Keyboard showing

键盘删除。布局应该回到初始状态,而是我得到这个

Should be back to initial state, but instead I get this

回答

0

解决方案:工具栏设置内容拥抱优先1.000,以避免它得到所有伸出。

相关问题