diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h index 80b9b10..5cbe64d 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h @@ -8,6 +8,10 @@ #import +@protocol TPKeyboardAvoidingAdditionsOptions +- (BOOL)TPKeyboardAvoiding_idealOffsetForViewAlwaysTop; +@end + @interface UIScrollView (TPKeyboardAvoidingAdditions) - (BOOL)TPKeyboardAvoiding_focusNextTextField; - (void)TPKeyboardAvoiding_scrollToActiveTextField; diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m index 06731cb..e164507 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m @@ -356,6 +356,11 @@ -(CGFloat)TPKeyboardAvoiding_idealOffsetForView:(UIView *)view withViewingAreaHe __block CGFloat offset = 0.0; CGRect subviewRect = [view convertRect:view.bounds toView:self]; + + // Allow views to specify their need to float to the top instead of towards the middle. + if ( [view respondsToSelector:@selector(TPKeyboardAvoiding_idealOffsetForViewAlwaysTop)] && [((id)view) TPKeyboardAvoiding_idealOffsetForViewAlwaysTop] ) { + return subviewRect.origin.y; + } __block CGFloat padding = 0.0; __block UIEdgeInsets contentInset;