Note that there are some explanatory texts on larger screens.

plurals
  1. POUITextView cursor below frame when changing frame
    primarykey
    data
    text
    <p>I have a <code>UIViewCOntroller</code>that contains a <code>UITextView</code>. When the keyboard appears I resize it like this:</p> <pre><code>#pragma mark - Responding to keyboard events - (void)keyboardDidShow:(NSNotification *)notification { NSDictionary* info = [notification userInfo]; CGRect keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect newTextViewFrame = self.textView.frame; newTextViewFrame.size.height -= keyboardSize.size.height + 70; self.textView.frame = newTextViewFrame; self.textView.backgroundColor = [UIColor yellowColor]; } - (void)keyboardWillHide:(NSNotification *)notification { NSDictionary* info = [notification userInfo]; CGRect keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect newTextViewFrame = self.textView.frame; newTextViewFrame.size.height += keyboardSize.size.height - 70; self.textView.frame = newTextViewFrame; } </code></pre> <p>The textView seems to rezise to the right size, but when the user types the cursor ends up "outside" the textView frame. See picture below:</p> <p><img src="https://i.stack.imgur.com/2CJqf.gif" alt="enter image description here"></p> <p>The yellow area is the <code>UITextView</code> frame (I don't know what the blue line next to the R key is). I find this quite wired. I'm using iOS7 if that makes any difference. </p> <p>Any ideas or tips?</p> <p><strong>Update</strong></p> <p>I have a UITextView subclass that draws horizontal lines with the following method (if that makes any difference):</p> <pre><code>- (void)drawRect:(CGRect)rect { //Get the current drawing context CGContextRef context = UIGraphicsGetCurrentContext(); //Set the line color and width CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:229.0/255.0 green:244.0/255.0 blue:255.0/255.0 alpha:1].CGColor); CGContextSetLineWidth(context, 1.0f); //Start a new Path CGContextBeginPath(context); //Find the number of lines in our textView + add a bit more height to draw lines in the empty part of the view NSUInteger numberOfLines = (self.contentSize.height + rect.size.height) / self.font.lineHeight; CGFloat baselineOffset = 6.0f; //iterate over numberOfLines and draw each line for (int x = 0; x &lt; numberOfLines; x++) { //0.5f offset lines up line with pixel boundary CGContextMoveToPoint(context, rect.origin.x, self.font.lineHeight*x + 0.5f + baselineOffset); CGContextAddLineToPoint(context, rect.size.width, self.font.lineHeight*x + 0.5f + baselineOffset); } // Close our Path and Stroke (draw) it CGContextClosePath(context); CGContextStrokePath(context); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload