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?

有帮助吗?

解决方案

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 ;)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top