0

I have UITextView:

textView = [[UITextView alloc] init];
textView.scrollEnabled = NO;

I have a problem only on iOS7:

On every keyboard keystroke, layoutSubviews is called on superview. After writing several characters, it gets stuck in infinite loop and keeps calling layoutSubviews constantly.

When I remove textView.scrollEnabled = NO; line of code, everything works the way it is supposed to.

I would really like to disable scrolling on my text view. Does anybody have an idea how to do it?

AndroC
  • 4,758
  • 2
  • 46
  • 69
  • are you overriding layoutSubviews in your class? – Max MacLeod Oct 29 '13 at 15:25
  • No. I only overriden it to prove my suspicion and delegated the call to super. This problem is most probably related to this one: http://stackoverflow.com/questions/18991001/in-ios-7-layoutsubviews-method-is-called-constantly-on-uibutton-subclass – AndroC Oct 29 '13 at 15:28

1 Answers1

0

In the end I hacked the whole thing by placing a Pan Gesture on UITextView. This way all functionalities of editing text view were preserved and scrolling was disabled. When I wanted to disable scrolling of text view, I didn't set scrollEnabled = NO. Instead I added Pan Gesture recognizer on UITextView. When I wanted to enable scrolling, I just removed that same Pan Gesture recognizer from text view.

Like this:

init method...

    _scrollDisablerGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(textViewScrollAction:)];
// method textViewScrollAction does nothing, empty implementation
    [_textView addGestureRecognizer:_scrollDisablerGR];

somewhere else in code:

if (shouldEnableScrolling) {
        [self.textView removeGestureRecognizer:_scrollDisablerGR];
    } else {
        if (!_scrollDisablerGR.view) {
            [self.textView addGestureRecognizer:_scrollDisablerGR];
        }
    }

Works great ;)

AndroC
  • 4,758
  • 2
  • 46
  • 69