From da34bb3d9f152c5fa6a3933dbbcf74c24b359ce5 Mon Sep 17 00:00:00 2001 From: Anthony Miller Date: Wed, 17 Jun 2015 11:00:13 -0700 Subject: [PATCH] Skip disabled text fields when using 'focusNextTextField' --- ...UIScrollView+TPKeyboardAvoidingAdditions.m | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m index 954b1eb1..1d6b30af 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m @@ -198,8 +198,7 @@ - (void)TPKeyboardAvoiding_findTextFieldAfterTextField:(UIView*)priorTextField b // Search recursively for text field or text view below priorTextField CGFloat priorFieldOffset = CGRectGetMinY([self convertRect:priorTextField.frame fromView:priorTextField.superview]); for ( UIView *childView in view.subviews ) { - if ( childView.hidden ) continue; - if ( ([childView isKindOfClass:[UITextField class]] || [childView isKindOfClass:[UITextView class]]) && childView.isUserInteractionEnabled) { + if ([self TPKeyboardAvoiding_viewIsNextTextField:childView]) { CGRect frame = [self convertRect:childView.frame fromView:view]; if ( childView != priorTextField && CGRectGetMinY(frame) >= priorFieldOffset @@ -215,6 +214,24 @@ - (void)TPKeyboardAvoiding_findTextFieldAfterTextField:(UIView*)priorTextField b } } +- (BOOL)TPKeyboardAvoiding_viewIsNextTextField:(UIView *)view { + if (view.hidden) return NO; + + if ([view isKindOfClass:[UITextField class]]) { + UITextField *textField = (UITextField *)view; + if (!textField.enabled) return NO; + + } + + if ( ([view isKindOfClass:[UITextField class]] || + [view isKindOfClass:[UITextView class]]) + && view.isUserInteractionEnabled) { + return YES; + } + + return NO; +} + - (void)TPKeyboardAvoiding_assignTextDelegateForViewsBeneathView:(UIView*)view { for ( UIView *childView in view.subviews ) { if ( ([childView isKindOfClass:[UITextField class]] || [childView isKindOfClass:[UITextView class]]) ) {