2012-12-04 72 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]; –

相关问题