简体   繁体   中英

Set UITextView on full screen in ios

I have set a UITextView on full screen of device like in iphone-5s,textView size is (0,44,320,524). when keyboard appear then user cant show the insert text in view.how can I manage the UITextView, can i use UIScrollView for it or any thing else?

While editing complete View will move up and after done editing will move down...

(void)textViewDidBeginEditing:(UITextView *)textView {
    [self animateTextView: YES];
}

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

(void) animateTextView:(BOOL) up {
    const int movementDistance =heightKeyboard; // tweak as needed
    const float movementDuration = 0.3f; // tweak as needed
    int movement= movement = (up ? -movementDistance : movementDistance);
    NSLog(@"%d",movement);
    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.inputView.frame, 0, movement);
    [UIView commitAnimations];
}

I hope it will work for you.

I have solved it by using this code

.h file define a value

 CGRect originalTextViewFrame;

.m file

  - (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;
  }

use scroll view and then after try

UITextViewDelegate 

method

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM