Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView to be resized with contentsize after pinch gesture of another view

Tags:

iphone

I am facing an issue of resizing UITextView in pinch gesture recognizer method. This gesture recognizer is for another view. I want that textview should also be resized along with that view.

I successfully able to resize UITextView according to requirement. But I have issue with text displayed in textview. After zooming in and zooming out for few times. contents inside UITextView does not come properly (see below image "After zooming in/out"). It decreases content width. I checked content size of UITextView, but it gives same width before resizing and after resizing.

Here, I have set text alignment to center for UITextView. I have also applied contentInset to UIEdgeInsetZero.

Any help will be appreciated.

Before zooming in/out Before zooming in/out

After zooming in/out After zooming in/out

like image 388
iMOBDEV Avatar asked Mar 28 '12 11:03

iMOBDEV


2 Answers

Are you calling setNeedsLayout on the parent view after you have altered the frame?

Try logging the bounds of the text view like so:

NSLog(@"Bounds: %@", NSStringFromCGRect(textView.bounds));
like image 93
Sam Avatar answered Nov 16 '22 12:11

Sam


I won't profess to be an expert on this, but it seems that UITextView wants to have a baseline of CGRectZero to work with, I have run into this very issue and my findings were that the problem presented itself when shrinking the UITextView, not when enlarging, so by overriding - (void)layoutSubviews like this:

- (void)layoutSubviews {
    CGRect bounds = self.bounds;
    self.bounds = CGRectZero;
    self.bounds = bounds;
}

in a subclass of UITextView this issue will be resolved. This definitely isn't the most elegant thing I've ever seen, but it's the only solution I've come up with.

like image 38
Trey Avatar answered Nov 16 '22 11:11

Trey