From c90aa4c1f205d9ebbc71a1d85d67ec029bc1a319 Mon Sep 17 00:00:00 2001
From: tristan <t@mrtristan.com>
Date: Wed, 27 Jan 2016 18:23:31 -0500
Subject: [PATCH] added TPKeyboardAvoidingAdditionsOptions protocol to allow
 for views to override specific pieces of functionality as needed added
 TPKeyboardAvoiding_idealOffsetForViewAlwaysTop to allow views to be able to
 float to the top instead of middle 	use case: have an 'autocomplete' style
 dropdown for one of my textfields. Need as much room as possible between the
 field and the keyboard, this will (safely) alter the math in calculating the
 scroll position so the textfield can specify that it needs to be on the top
 instead of the middle

# Conflicts:
#	TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m
---
 .../UIScrollView+TPKeyboardAvoidingAdditions.h               | 4 ++++
 .../UIScrollView+TPKeyboardAvoidingAdditions.m               | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h
index 80b9b109..5cbe64d3 100644
--- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h
+++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h
@@ -8,6 +8,10 @@
 
 #import <UIKit/UIKit.h>
 
+@protocol TPKeyboardAvoidingAdditionsOptions <NSObject>
+- (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 06731cb6..e164507e 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<TPKeyboardAvoidingAdditionsOptions>)view) TPKeyboardAvoiding_idealOffsetForViewAlwaysTop] ) {
+        return subviewRect.origin.y;
+    }
 
     __block CGFloat padding = 0.0;
     __block UIEdgeInsets contentInset;