Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion RDRStickyKeyboardView/RDRStickyKeyboardView.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,29 @@

@end

#pragma mark - RDRStickyKeyboardViewDelegate

@protocol RDRStickyKeyboardViewDelegate <NSObject>

-(void)didSelectLeftKeyboardButton;
-(void)didSelectRightKeyboardButton;

@end

#pragma mark - RDRStickyKeyboardView

@interface RDRStickyKeyboardView : UIView

/**
* Delegate to notify about left/right button actions.
*/
@property(nonatomic, weak) id<RDRStickyKeyboardViewDelegate> delegate;

/**
* The UITextView instance from the inputViewScrollView to be accessed by external classes to be able to handle text content and delegation.
*/
@property(nonatomic, readonly) UITextView * textView;

@property (nonatomic, strong, readonly) UIScrollView *scrollView;

// The inputView that is always visible, right below the content.
Expand All @@ -73,7 +92,10 @@
@property (nonatomic, strong, readonly) RDRKeyboardInputView *inputView;

// Designated initializer
- (instancetype)initWithScrollView:(UIScrollView *)scrollView;
- (instancetype)initWithScrollView:(UIScrollView *)scrollView
delegate:(id<RDRStickyKeyboardViewDelegate>)delegate
leftButton:(UIButton *)leftButtonOrNil
rightButton:(UIButton *)rightButtonOrNil;

- (void)showKeyboard;
- (void)hideKeyboard;
Expand Down
78 changes: 64 additions & 14 deletions RDRStickyKeyboardView/RDRStickyKeyboardView.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ static inline UIViewAnimationOptions RDRAnimationOptionsForCurve(UIViewAnimation
#define RDR_KEYBOARD_INPUT_VIEW_MARGIN_BUTTONS_VERTICAL 7

@interface RDRKeyboardInputView () {
UITextView *_textView;
UIButton *_leftButton;
UIButton *_rightButton;

}

@property (nonatomic, strong) UIButton *leftButton;
@property (nonatomic, strong) UIButton *rightButton;
@property (nonatomic, strong) UITextView *textView;


@property (nonatomic, strong, readonly) UIToolbar *toolbar;

@end
Expand All @@ -231,6 +234,17 @@ - (id)initWithFrame:(CGRect)frame
return self;
}

-(id)initWithLeftButton:(UIButton *)leftButtonOrNil rightButton:(UIButton *)rightButtonOrNil
{
if (self = [super init]) {
self.leftButton = leftButtonOrNil;
self.rightButton = rightButtonOrNil;
[self _setupSubviews];
}

return self;
}

#pragma mark - NSCoding

- (id)initWithCoder:(NSCoder *)decoder
Expand Down Expand Up @@ -280,11 +294,7 @@ - (UIButton *)leftButton
return _leftButton;
}

_leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
_leftButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];

[_leftButton setTitle:NSLocalizedString(@"Other", nil)
forState:UIControlStateNormal];
_leftButton = [[UIButton alloc] initWithFrame:CGRectZero];

return _leftButton;
}
Expand All @@ -295,11 +305,7 @@ - (UIButton *)rightButton
return _rightButton;
}

_rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
_rightButton.titleLabel.font = [UIFont systemFontOfSize:14.0f];

[_rightButton setTitle:NSLocalizedString(@"Send", nil)
forState:UIControlStateNormal];
_rightButton = [[UIButton alloc] initWithFrame:CGRectZero];

return _rightButton;
}
Expand Down Expand Up @@ -481,16 +487,26 @@ @interface RDRStickyKeyboardView () {

@property (nonatomic, strong, readonly) RDRKeyboardInputView *inputViewKeyboard;

@property(nonatomic, strong) UIButton * leftButton;
@property(nonatomic, strong) UIButton * rightButton;

@end

@implementation RDRStickyKeyboardView

#pragma mark - Lifecycle

- (instancetype)initWithScrollView:(UIScrollView *)scrollView
delegate:(id<RDRStickyKeyboardViewDelegate>)delegate
leftButton:(UIButton *)leftButtonOrNil
rightButton:(UIButton *)rightButtonOrNil
{
if (self = [super init])
{
self.leftButton = leftButtonOrNil;
self.rightButton = rightButtonOrNil;
self.delegate = delegate;

_scrollView = scrollView;
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight;
Expand All @@ -500,6 +516,9 @@ - (instancetype)initWithScrollView:(UIScrollView *)scrollView

[self _setupSubviews];
[self _registerForNotifications];
//setup the actions for the buttons
[self _setupKeyboardButtonActions];

}

return self;
Expand All @@ -524,7 +543,7 @@ - (RDRKeyboardInputView *)inputViewKeyboard
- (RDRKeyboardInputView *)inputViewScrollView
{
if (!_inputViewScrollView) {
_inputViewScrollView = [RDRKeyboardInputView new];
_inputViewScrollView = [[RDRKeyboardInputView alloc] initWithLeftButton:self.leftButton rightButton:self.rightButton];
}

return _inputViewScrollView;
Expand All @@ -535,6 +554,11 @@ - (RDRKeyboardInputView *)inputView
return self.inputViewKeyboard;
}

-(UITextView *)textView
{
return self.inputViewScrollView.textView;
}

#pragma mark - Overrides

- (void)willMoveToSuperview:(UIView *)newSuperview
Expand Down Expand Up @@ -563,6 +587,32 @@ - (void)hideKeyboard

#pragma mark - Private

-(void)_setupKeyboardButtonActions
{
// inputViewScrollView
[self.inputViewScrollView.leftButton addTarget:self action:@selector(onLeftKeyboardButtonTap:) forControlEvents:UIControlEventTouchUpInside];

[self.inputViewScrollView.rightButton addTarget:self action:@selector(onRightKeyboardButtonTap:) forControlEvents:UIControlEventTouchUpInside];


// inputViewKeyboard
[self.inputViewKeyboard.leftButton addTarget:self action:@selector(onLeftKeyboardButtonTap:) forControlEvents:UIControlEventTouchUpInside];

[self.inputViewKeyboard.rightButton addTarget:self action:@selector(onRightKeyboardButtonTap:) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - Keyboard Actions handlers

-(IBAction)onLeftKeyboardButtonTap:(id)sender
{
[self.delegate didSelectLeftKeyboardButton];
}

-(IBAction)onRightKeyboardButtonTap:(id)sender
{
[self.delegate didSelectRightKeyboardButton];
}

- (void)_setupSubviews
{
// Add scrollview as subview
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

static NSString * const CellIdentifier = @"cell";

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>
@interface ViewController () <UITableViewDataSource, UITableViewDelegate, UITextViewDelegate, RDRStickyKeyboardViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) RDRStickyKeyboardView *contentWrapper;
Expand Down Expand Up @@ -60,11 +60,20 @@ - (void)_setupSubviews
|UIViewAutoresizingFlexibleHeight;
[self.tableView registerClass:[UITableViewCell class]
forCellReuseIdentifier:CellIdentifier];


//configure the stickyKeyboardView
UIButton * rightButton = [self newButtonWithTitle:NSLocalizedString(@"Send", nil)];
UIButton * leftButton = [self newButtonWithTitle:NSLocalizedString(@"Other", nil)];

RDRStickyKeyboardView * stickyKeyboardView = [[RDRStickyKeyboardView alloc] initWithScrollView:self.tableView delegate:self leftButton:leftButton rightButton:rightButton];

stickyKeyboardView.frame = self.view.bounds;
stickyKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
stickyKeyboardView.textView.delegate = self;

// Setup wrapper
self.contentWrapper = [[RDRStickyKeyboardView alloc] initWithScrollView:self.tableView];
self.contentWrapper.frame = self.view.bounds;
self.contentWrapper.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.contentWrapper = stickyKeyboardView;

[self.view addSubview:self.contentWrapper];
}

Expand Down Expand Up @@ -94,4 +103,57 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
return 1;
}

#pragma mark - RDRStickyKeyboardViewDelegate

-(void)didSelectLeftKeyboardButton
{
[self onCancelTap:nil];
}
-(void)didSelectRightKeyboardButton
{
[self onDoneTap:nil];
}

#pragma mark - Actions

-(IBAction)onDoneTap:(id)sender
{
NSLog(@"Send tapped!!");
}

-(IBAction)onCancelTap:(id)sender
{
NSLog(@"Other tapped!!");
}

#pragma mark - UITextViewDelegate

- (void)textViewDidBeginEditing:(UITextView *)textView{
NSLog(@"textViewDidBeginEditing!!..");
}


- (void)textViewDidEndEditing:(UITextView *)textView{
NSLog(@"textViewDidEndEditing!!..");

}

#pragma mark - Utilities

- (UIButton *)newButtonWithTitle:(NSString *)title
{
UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
button.titleLabel.font = [UIFont systemFontOfSize:14.0f];

[button setTitle:title
forState:UIControlStateNormal];
return button;
}


-(void)hideKeyboard
{
[self.view endEditing:YES];
}

@end
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,39 @@ Check out the sample project to learn more.

```objectivec
UITableView *tableView = ...;
RDRStickyKeyboardView *keyboardView = [[RDRStickyKeyboardView alloc] initWithScrollView:tableView];
keyboardView.frame = self.view.bounds;
keyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self.view addSubview:keyboardView];
//create your own buttons to show on the keyboard
UIButton * rightButton = ...;
UIButton * leftButton = ...;

RDRStickyKeyboardView * stickyKeyboardView = [[RDRStickyKeyboardView alloc] initWithScrollView:tableView delegate:self leftButton:leftButton rightButton:rightButton];

stickyKeyboardView.frame = self.view.bounds;
stickyKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
//set delegate to receive left/right button actions
stickyKeyboardView.textView.delegate = self;

[self.view addSubview:stickyKeyboardView];
```

## RDRStickyKeyboardViewDelegate
In order to catch when the user Taps on the left/right buttons of the keyboard, you must conform to the RDRStickyKeyboardViewDelegate protocol.

```objectivec
-(void)didSelectLeftKeyboardButton
{
//code for handling left keyboard button Tap
}
-(void)didSelectRightKeyboardButton
{
//code for handling right keyboard button Tap
}
```

## Accessing the UITextView
You have readOnly access to the UITextView shown as a convenience property 'textView' of the RDRStickyKeyboardView class.
Use it to access text content as well as for implementing UITextViewDelegate if your code requires this (see demo project for more info on this).


## Requirements
* ARC
* iOS 7
Expand Down