|
1 | 1 | #import "RNToastView.h"
|
2 | 2 |
|
3 |
| -@implementation RNToastView |
| 3 | +@implementation RNToastView { |
| 4 | + CGRect originalFrame; |
| 5 | +} |
4 | 6 |
|
5 | 7 | - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
|
6 | 8 | id hitView = [super hitTest:point withEvent:event];
|
7 | 9 | if (hitView == self) return nil;
|
8 | 10 | else return hitView;
|
9 | 11 | }
|
10 | 12 |
|
| 13 | +- (instancetype)initWithFrame:(CGRect)frame kbdHeight: (CGFloat)kbdHeight kbdAvoidEnabled: (BOOL)kbdAvoidEnabled { |
| 14 | + originalFrame = frame; |
| 15 | + if (kbdAvoidEnabled) { |
| 16 | + frame.size.height -= kbdHeight; |
| 17 | + } |
| 18 | + if (self = [super initWithFrame:frame]) { |
| 19 | + if (kbdAvoidEnabled) { |
| 20 | + [[NSNotificationCenter defaultCenter] addObserver:self |
| 21 | + selector:@selector(keyboardWillShow:) |
| 22 | + name:UIKeyboardWillShowNotification |
| 23 | + object:nil]; |
| 24 | + [[NSNotificationCenter defaultCenter] addObserver:self |
| 25 | + selector:@selector(keyboardWillHide:) |
| 26 | + name:UIKeyboardWillHideNotification |
| 27 | + object:nil]; |
| 28 | + } |
| 29 | + } |
| 30 | + return self; |
| 31 | +} |
| 32 | + |
| 33 | +- (void)keyboardWillShow:(NSNotification *)notification { |
| 34 | + CGSize keyboardSize = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size; |
| 35 | + CGFloat height = keyboardSize.height; |
| 36 | + CGRect frame = originalFrame; |
| 37 | + frame.size.height -= height; |
| 38 | + [self setFrame: frame]; |
| 39 | +} |
| 40 | + |
| 41 | +- (void)keyboardWillHide:(NSNotification *)notification { |
| 42 | + [self setFrame: originalFrame]; |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +- (void)dealloc { |
| 47 | + [[NSNotificationCenter defaultCenter] removeObserver:self |
| 48 | + name:UIKeyboardWillShowNotification |
| 49 | + object:nil]; |
| 50 | + [[NSNotificationCenter defaultCenter] removeObserver:self |
| 51 | + name:UIKeyboardWillHideNotification |
| 52 | + object:nil]; |
| 53 | +} |
| 54 | + |
11 | 55 | @end
|
0 commit comments