2015-03-27 2 views
-1

Я установил UITextView на полноэкранном режиме устройства, например, в iphone-5s, textView размером (0,44,320,524). когда клавиатура появляется, пользователь не может показать текст вставки в виде. Как я могу управлять UITextView, могу ли я использовать UIScrollView для него или что-то еще?Установить UITextView на весь экран в ios

+0

Я думаю, что вы можете найти ответ на свой вопрос здесь: http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when -keyboard-это-настоящее – Gautier

ответ

2
  1. При редактировании полного представления будет двигаться вверх и после завершения редактирования будет двигаться вниз ...

    • (аннулируются) textViewDidBeginEditing: (UITextView *) TextView {[само animateTextView: YES]; }

    • (void) textViewDidEndEditing: (UITextView *) textView {[self animateTextView: NO]; }

    • (void) animateTextView: (BOOL) up { const int movementDistance = heightKeyboard; // подстраивать по мере необходимости const float movementDuration = 0.3f; // подстраивать по мере необходимости int движение = движение = (вверх? -movementDistance: movementDistance); NSLog (@ "% d", движение);

      [UIView beginAnimations: @"anim" context: nil]; 
      [UIView setAnimationBeginsFromCurrentState: YES]; 
      [UIView setAnimationDuration: movementDuration]; 
      self.view.frame = CGRectOffset(self.inputView.frame, 0, movement); 
      [UIView commitAnimations]; 
      

      } Я надеюсь, что это сработает для вас.

0

вид использования прокрутки, а затем после попробовать

UITextViewDelegate 

метод

- (void)textViewDidBeginEditing:(UITextView *)textView 
{ 
    [scrollView setContentOffset:CGPointMake(0,yourtextview.center.y-200) animated:YES]; 
} 
1

я решил его с помощью этого кода

.h файл определения значения

CGRect originalTextViewFrame; 

.m файл

- (void)viewWillAppear:(BOOL)animated 
    { 
    // Register notifications for when the keyboard appears 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 
    } 

    - (void)viewWillDisappear:(BOOL)animated 
    { 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
    } 

    - (void)keyboardWillShow:(NSNotification*)notification 
    { 
    [self moveTextViewForKeyboard:notification up:YES]; 
    } 

    - (void)keyboardWillHide:(NSNotification*)notification 
    { 
    [self moveTextViewForKeyboard:notification up:NO]; 
    } 
    - (void)moveTextViewForKeyboard:(NSNotification*)notification up:(BOOL)up 
    { 
    NSDictionary *userInfo = [notification userInfo]; 
    NSTimeInterval animationDuration; 
    UIViewAnimationCurve animationCurve; 
    CGRect keyboardRect; 
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve]; 
animationDuration = [[userInfo  objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 
keyboardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
keyboardRect = [self.view convertRect:keyboardRect fromView:nil]; 
[UIView beginAnimations:@"ResizeForKeyboard" context:nil]; 
[UIView setAnimationDuration:animationDuration]; 
[UIView setAnimationCurve:animationCurve]; 

if (up == YES) { 
CGFloat keyboardTop = keyboardRect.origin.y; 
CGRect newTextViewFrame = textView.frame; 
originalTextViewFrame = textView.frame; 
newTextViewFrame.size.height = keyboardTop - textView.frame.origin.y - 10; 
textView.frame = newTextViewFrame; 
}  
else 
{ 
// Keyboard is going away (down) - restore original frame 
    textView.frame = originalTextViewFrame; 
    } 

[UIView commitAnimations]; 
} 

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text 
    { 
    // Any new character added is passed in as the "text" parameter 
    if ([text isEqualToString:@"\n"]) 
    { 
    // Be sure to test for equality using the "isEqualToString" message 
    [textView resignFirstResponder]; 
    //[scrlView setContentOffset:CGPointMake(0,0) animated:YES]; 

    // Return FALSE so that the final '\n' character doesn't get added 
    return FALSE; 
    } 
    // For any other character return TRUE so that the text gets added to the view 
    return TRUE; 
    } 
Смежные вопросы