Skip to content

Commit

Permalink
added TPKeyboardAvoidingAdditionsOptions protocol to allow for views …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mrtristan authored and michaeltyson committed Nov 8, 2020
1 parent 00546d1 commit c90aa4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#import <UIKit/UIKit.h>

@protocol TPKeyboardAvoidingAdditionsOptions <NSObject>
- (BOOL)TPKeyboardAvoiding_idealOffsetForViewAlwaysTop;
@end

@interface UIScrollView (TPKeyboardAvoidingAdditions)
- (BOOL)TPKeyboardAvoiding_focusNextTextField;
- (void)TPKeyboardAvoiding_scrollToActiveTextField;
Expand Down
5 changes: 5 additions & 0 deletions TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c90aa4c

Please sign in to comment.