diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index 909b907..665b189 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -21,8 +21,6 @@ #import #endif -#define KEYBOARD_HEIGHT 80 -#define PREDICTION_BAR_HEIGHT 40 #define ADD_BUTTON_PADDING 10.0f #define DEFAULT_WINDOW_WIDTH 240 @@ -62,6 +60,9 @@ @interface SCLAlertView () @property (nonatomic) CGFloat subTitleHeight; @property (nonatomic) CGFloat subTitleY; +@property (nonatomic) CGPoint tmpContentViewFrameOrigin; +@property (nonatomic) CGPoint tmpCircleViewFrameOrigin; + @end @implementation SCLAlertView @@ -646,25 +647,48 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField - (void)keyboardWillShow:(NSNotification *)notification { if(_keyboardIsVisible) return; - - [UIView animateWithDuration:0.2f animations:^{ - CGRect f = self.view.frame; - f.origin.y -= KEYBOARD_HEIGHT + PREDICTION_BAR_HEIGHT; - self.view.frame = f; - }]; + + NSDictionary *userInfo = [notification userInfo]; + CGRect endKeyBoardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; + CGFloat endKeyBoardFrame = CGRectGetMinY(endKeyBoardRect); + _keyboardIsVisible = YES; + + _tmpContentViewFrameOrigin = _contentView.frame.origin; + _tmpCircleViewFrameOrigin = _circleViewBackground.frame.origin; + + CGFloat newContentViewFrameY = CGRectGetMaxY(_contentView.frame) - endKeyBoardFrame; + + if(!IS_LANDSCAPE && newContentViewFrameY < 0) { + newContentViewFrameY = 0; + } + + CGFloat newBallViewFrameY = _circleViewBackground.frame.origin.y - fabs(newContentViewFrameY); + + CGRect contentFrame = self.contentView.frame; + contentFrame.origin.y -= fabs(newContentViewFrameY); + self.contentView.frame = contentFrame; + + CGRect circleFrame = self.circleViewBackground.frame; + circleFrame.origin.y = newBallViewFrameY; + self.circleViewBackground.frame = circleFrame; } - (void)keyboardWillHide:(NSNotification *)notification { - if(!_keyboardIsVisible) return; - - [UIView animateWithDuration:0.2f animations:^{ - CGRect f = self.view.frame; - f.origin.y += KEYBOARD_HEIGHT + PREDICTION_BAR_HEIGHT; - self.view.frame = f; - }]; - _keyboardIsVisible = NO; + if(_keyboardIsVisible) { + CGRect contentFrame = self.contentView.frame; + contentFrame.origin.y = _tmpContentViewFrameOrigin.y; + self.contentView.frame = contentFrame; + _tmpContentViewFrameOrigin = CGPointZero; + + CGRect circleFrame = self.circleViewBackground.frame; + circleFrame.origin.y = _tmpCircleViewFrameOrigin.y; + self.circleViewBackground.frame = circleFrame; + _tmpCircleViewFrameOrigin = CGPointZero; + + _keyboardIsVisible = NO; + } } #pragma mark - Buttons diff --git a/SCLAlertView/SCLMacros.h b/SCLAlertView/SCLMacros.h index 1fec837..ee61d5d 100644 --- a/SCLAlertView/SCLMacros.h +++ b/SCLAlertView/SCLMacros.h @@ -24,4 +24,6 @@ blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) +#define IS_LANDSCAPE UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) + #endif