keyboard hiding my textview
        Posted  
        
            by 
                Risma 
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Risma 
        
        
        
        Published on 2010-12-30T05:09:25Z
        Indexed on 
            2010/12/30
            5:54 UTC
        
        
        Read the original article
        Hit count: 331
        
hi guys
i have a simple app, it consist of 2 textview, 1 uiview as a coretext subclass, and then 1 scrollview. the others part is subviews from scrollview. I use this scrollview because i need to scroll the textviews and uiview at the same time. I already scroll all of them together, but the problem is, the keyboard hiding some lines in the textview. I have to change the frame of scrollview when keyboard appear, but it still not help. This is my code :
UIScrollView *scrollView;
UIView *viewTextView;
UITextView *lineNumberTextView;
UITextView *codeTextView;
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] 
 addObserver:self 
 selector:@selector(keyboardWillAppear:) 
 name:UIKeyboardWillShowNotification 
 object:nil];
[[NSNotificationCenter defaultCenter] 
 addObserver:self 
 selector:@selector(keyboardWillDisappear:) 
 name:UIKeyboardWillHideNotification 
 object:nil];
self.scrollView.frame = CGRectMake(0, 88, self.codeTextView.frame.size.width, 
                                           self.codeTextView.frame.size.height);
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, viewTextView.frame.size.height);
[scrollView addSubview:viewTextView];
CGAffineTransform translationCoreText = CGAffineTransformMakeTranslation(60, 7);
[viewTextView setTransform:translationCoreText];
[scrollView addSubview:lineNumberTextView];
[self.scrollView setScrollEnabled:YES];
[self.codeTextView setScrollEnabled:NO];
}
-(void)keyboardWillAppear:(NSNotification *)notification {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[[[notification userInfo] 
                               objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; 
CGRect keyboardEndingUncorrectedFrame = [[[notification userInfo] 
                                          objectForKey:UIKeyboardFrameEndUserInfoKey ] CGRectValue];
CGRect keyboardEndingFrame = 
[self.view convertRect:keyboardEndingUncorrectedFrame 
              fromView:nil];
self.scrollView.frame = CGRectMake(0, 88, self.codeTextView.frame.size.width, 
                                           self.codeTextView.frame.size.height - keyboardEndingFrame.size.height);
[UIView commitAnimations];
}
-(void)keyboardWillDisappear:(NSNotification *) notification {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[[[notification userInfo] 
                               objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; 
CGRect keyboardEndingUncorrectedFrame = [[[notification userInfo] 
                                          objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect keyboardEndingFrame = 
[self.view convertRect:keyboardEndingUncorrectedFrame 
              fromView:nil];
self.scrollView.frame = CGRectMake(0, 88, self.codeTextView.frame.size.width, 
                                           self.codeTextView.frame.size.height + keyboardEndingFrame.size.height);
[UIView commitAnimations];
}
can somebody help me please?
© Stack Overflow or respective owner