|
17 | 17 | @import AVFoundation; |
18 | 18 | @import AudioToolbox; |
19 | 19 |
|
20 | | -#define KEYBOARD_HEIGHT 80 |
21 | | -#define PREDICTION_BAR_HEIGHT 40 |
22 | 20 | #define ADD_BUTTON_PADDING 10.0f |
23 | 21 | #define DEFAULT_WINDOW_WIDTH 240 |
24 | 22 |
|
@@ -58,6 +56,9 @@ @interface SCLAlertView () <UITextFieldDelegate, UIGestureRecognizerDelegate> |
58 | 56 | @property (nonatomic) CGFloat subTitleHeight; |
59 | 57 | @property (nonatomic) CGFloat subTitleY; |
60 | 58 |
|
| 59 | +@property (nonatomic) CGPoint tmpContentViewFrameOrigin; |
| 60 | +@property (nonatomic) CGPoint tmpCircleViewFrameOrigin; |
| 61 | + |
61 | 62 | @end |
62 | 63 |
|
63 | 64 | @implementation SCLAlertView |
@@ -670,25 +671,48 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField |
670 | 671 | - (void)keyboardWillShow:(NSNotification *)notification |
671 | 672 | { |
672 | 673 | if(_keyboardIsVisible) return; |
673 | | - |
674 | | - [UIView animateWithDuration:0.2f animations:^{ |
675 | | - CGRect f = self.view.frame; |
676 | | - f.origin.y -= KEYBOARD_HEIGHT + PREDICTION_BAR_HEIGHT; |
677 | | - self.view.frame = f; |
678 | | - }]; |
| 674 | + |
| 675 | + NSDictionary *userInfo = [notification userInfo]; |
| 676 | + CGRect endKeyBoardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; |
| 677 | + CGFloat endKeyBoardFrame = CGRectGetMinY(endKeyBoardRect); |
| 678 | + |
679 | 679 | _keyboardIsVisible = YES; |
| 680 | + |
| 681 | + _tmpContentViewFrameOrigin = _contentView.frame.origin; |
| 682 | + _tmpCircleViewFrameOrigin = _circleViewBackground.frame.origin; |
| 683 | + |
| 684 | + CGFloat newContentViewFrameY = CGRectGetMaxY(_contentView.frame) - endKeyBoardFrame; |
| 685 | + |
| 686 | + if(!IS_LANDSCAPE && newContentViewFrameY < 0) { |
| 687 | + newContentViewFrameY = 0; |
| 688 | + } |
| 689 | + |
| 690 | + CGFloat newBallViewFrameY = _circleViewBackground.frame.origin.y - fabs(newContentViewFrameY); |
| 691 | + |
| 692 | + CGRect contentFrame = self.contentView.frame; |
| 693 | + contentFrame.origin.y -= fabs(newContentViewFrameY); |
| 694 | + self.contentView.frame = contentFrame; |
| 695 | + |
| 696 | + CGRect circleFrame = self.circleViewBackground.frame; |
| 697 | + circleFrame.origin.y = newBallViewFrameY; |
| 698 | + self.circleViewBackground.frame = circleFrame; |
680 | 699 | } |
681 | 700 |
|
682 | 701 | - (void)keyboardWillHide:(NSNotification *)notification |
683 | 702 | { |
684 | | - if(!_keyboardIsVisible) return; |
685 | | - |
686 | | - [UIView animateWithDuration:0.2f animations:^{ |
687 | | - CGRect f = self.view.frame; |
688 | | - f.origin.y += KEYBOARD_HEIGHT + PREDICTION_BAR_HEIGHT; |
689 | | - self.view.frame = f; |
690 | | - }]; |
691 | | - _keyboardIsVisible = NO; |
| 703 | + if(_keyboardIsVisible) { |
| 704 | + CGRect contentFrame = self.contentView.frame; |
| 705 | + contentFrame.origin.y = _tmpContentViewFrameOrigin.y; |
| 706 | + self.contentView.frame = contentFrame; |
| 707 | + _tmpContentViewFrameOrigin = CGPointZero; |
| 708 | + |
| 709 | + CGRect circleFrame = self.circleViewBackground.frame; |
| 710 | + circleFrame.origin.y = _tmpCircleViewFrameOrigin.y; |
| 711 | + self.circleViewBackground.frame = circleFrame; |
| 712 | + _tmpCircleViewFrameOrigin = CGPointZero; |
| 713 | + |
| 714 | + _keyboardIsVisible = NO; |
| 715 | + } |
692 | 716 | } |
693 | 717 |
|
694 | 718 | #pragma mark - Buttons |
|
0 commit comments