From cc2b36e5939f8bf2fcc6e4aeca4bffe5e50d0663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20C=C5=93ur?= Date: Fri, 2 Dec 2011 10:12:07 +0100 Subject: [PATCH] UIKeyboardBoundsUserInfoKey is deprecated --- TSAlertView/TSAlertView.m | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/TSAlertView/TSAlertView.m b/TSAlertView/TSAlertView.m index 55fdaf4..96527e7 100644 --- a/TSAlertView/TSAlertView.m +++ b/TSAlertView/TSAlertView.m @@ -570,26 +570,22 @@ - (CGSize)recalcSizeAndLayout:(BOOL)layout - (void)onKeyboardWillShow:(NSNotification *)note { - NSValue *boundsValue = - [[note userInfo] objectForKey:UIKeyboardBoundsUserInfoKey]; - NSValue *centerValue = - [[note userInfo] objectForKey:UIKeyboardCenterEndUserInfoKey]; - CGPoint kbCenter = [[self superview] convertPoint:[centerValue CGPointValue] - fromView:nil]; - CGRect kbBounds = [boundsValue CGRectValue]; - CGRect kbFrame = CGRectOffset(kbBounds, - kbCenter.x - kbBounds.size.width / 2., - kbCenter.y - kbBounds.size.height / 2.); + #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2 + NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]; + #else + NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey]; + #endif + CGRect keyboardFrame = [[self superview] convertRect:[keyboardBoundsValue CGRectValue] fromView:nil]; - if (CGRectIntersectsRect([self frame], kbFrame)) { + if (CGRectIntersectsRect([self frame], keyboardFrame)) { CGPoint c = [self center]; - - if ([self frame].size.height > kbFrame.origin.y - 20.) { - [self setMaxHeight:kbFrame.origin.y - 20.]; + CGFloat y = self.superview.bounds.size.height - MIN(keyboardFrame.size.width, keyboardFrame.size.height); + if ([self frame].size.height > y - 20.) { + [self setMaxHeight:y - 20.]; [self sizeToFit]; [self layoutSubviews]; } - c.y = kbFrame.origin.y / 2.; + c.y = y / 2.; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.2]; [self setCenter:c];