문제

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