2012-12-04 34 views

回答

4

您可以減少整型尺寸你的TextView在鍵盤出現

-(void)textViewDidBeginEditing:(UITextView *)textView 
{ 
    CGRect frame = txtAddNote.frame; 
    frame.size.height = 150; //Decrease your textView height at this time 
    txtAddNote.frame = frame; 
} 
-(IBAction)DoneBarBtnPress:(id)sender 
{ 
    CGRect frame = txtAddNote.frame; 
    frame.size.height = 212; //Original Size of textView 
    txtAddNote.frame = frame; 

    //Keyboard dismiss 
    [self.view endEditing:YES]; 
} 
1

只是滾動視圖時UITextView開始編輯這樣的..

-(void)textViewDidBeginEditing:(UITextView *)textView 
{ 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.3]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, -160, self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 

} 

和endEditing只是設置默認屏幕像波紋管..

-(void)textViewDidEndEditing:(UITextView *)textView 
{ 
    [textView resignFirstResponder]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, 0, self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
} 

UPDATE

這裏有您的要求我們設置框架與我們的看法見波紋管代碼

-(void)textViewDidBeginEditing:(UITextView *)textView 
    { 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.3]; 
     [yourTextView setFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,self.view.‌​frame.size.width,self.view.frame.size.height - 160)]; 
     [UIView commitAnimations]; 

    } 

-(void)textViewDidEndEditing:(UITextView *)textView 
    { 
     [textView resignFirstResponder]; 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.3]; 
     [yourTextView setFrame:self.view]; 
     [UIView commitAnimations]; 
    } 
+0

這些動畫使用塊更具可讀性。 – dasdom

+0

不,這根本不起作用。我有一個工具欄在頂部,有一個'後退'按鈕和一個'完成'按鈕。然後我有一個UITextView幾乎和視圖本身一樣大。所以當我做你的方法時,視圖只是向上移動,然後工具欄不再可達。完成後,這不會使我的UITextView可滾動,而我選擇了IB中的可滾動選項,並且可以在不編輯它時滾動它。 –

+0

@frénésie只需添加此行並測試它。[yourTextView setScrollsToTop:YES]; –

相關問題