2016-04-24 65 views
0

當鍵盤出現時我想用Autolayoutview1來調整,我也有view2屏幕像這條底線:之間調整大小的UIView使用自動佈局與修復底部的UIView

enter image description here

layoutConstraintview1 & view2

enter image description here

我創建了th ËIBOutlet,這樣做,

-(void)keyboardWillShow:(NSNotification*)n { 

    NSDictionary *info = n.userInfo; 
    NSValue  *value = info[UIKeyboardFrameEndUserInfoKey]; 
    CGRect rawFrame  = [value CGRectValue]; 
    CGRect keyboardFrame = [self.view convertRect:rawFrame fromView:nil]; 

    _blc.constant = CGRectGetHeight(keyboardFrame)-35; 
    [self.view layoutIfNeeded]; 
} 


-(void)keyboardWillHide:(NSNotification*)n { 
    _blc.constant = 0.0; 
    [self.view layoutIfNeeded]; 
} 

view2height 35所以當鍵盤出現和消失有view1下一個可見的縫隙像這樣

enter image description here

我故意給基地UIView一個水上顏色講述差距。

調整view1的尺寸時,我該如何彌補這個空白?

+0

當你說_blc.constant = CGRectGetHeight(keyboardFrame)時會發生什麼;? – beyowulf

+0

當鍵盤出現和消失時,同樣的問題間隙仍然可見。 –

回答

0

所以如果我已經把它做對了,你想要做的是用鍵盤調整View1的大小,並在其下面放置View2? 如果就是這樣,你的看法是這樣的:

-------------- 
View1 
View2 
-------------- 

你應該從View1.bottom> = View2.top 0常數的垂直空間的限制;和另一個垂直空間約束從View1.bottom到Superview.bottom =(無論接口生成器暗示你)。你想要IBOutlet的約束是最後一個。

當鍵盤出現/消失時,像之前那樣更新它的常量。這應該做到這一點。

希望它有幫助!

+0

不工作,當鍵盤出現和消失時,相同的問題間隙仍然可見。 –

+0

你如何更新約束? – facumenzella

+0

正如你所說的最後一個在view1和superview底部佈局指南之間。當在Xcode中設置它的常量是35.0,並且當keyboardWillAppear時,我將常量設置爲與鍵盤高度相同。但同樣的問題仍然可見。它在模擬器中可以很容易看到,動畫效果很慢。 –