From: Grant Paul Date: Sat, 11 Jun 2011 07:27:01 +0000 (-0700) Subject: Let Apple do the keyboard handling and resizing for us; much easier than trying to... X-Git-Url: https://git.saurik.com/cydia.git/commitdiff_plain/f877e0b9fb8e7be5641ed775f94efda4739b66b9 Let Apple do the keyboard handling and resizing for us; much easier than trying to do it manually. --- diff --git a/MobileCydia.mm b/MobileCydia.mm index a6367fcc..49245cc4 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -6263,86 +6263,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; } -- (void) resizeForKeyboardBounds:(CGRect)bounds duration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve { - CGRect base = [[self view] bounds]; - base.size.height -= bounds.size.height; - base.origin = [list_ frame].origin; - - [UIView beginAnimations:nil context:NULL]; - [UIView setAnimationBeginsFromCurrentState:YES]; - [UIView setAnimationCurve:curve]; - [UIView setAnimationDuration:duration]; - [list_ setFrame:base]; - [UIView commitAnimations]; -} - -- (void) resizeForKeyboardBounds:(CGRect)bounds duration:(NSTimeInterval)duration { - [self resizeForKeyboardBounds:bounds duration:duration curve:UIViewAnimationCurveLinear]; -} - -- (void) resizeForKeyboardBounds:(CGRect)bounds { - [self resizeForKeyboardBounds:bounds duration:0]; -} - -- (void) getKeyboardCurve:(UIViewAnimationCurve *)curve duration:(NSTimeInterval *)duration forNotification:(NSNotification *)notification { - if (&UIKeyboardAnimationCurveUserInfoKey == NULL) - *curve = UIViewAnimationCurveEaseInOut; - else - [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:curve]; - - if (&UIKeyboardAnimationDurationUserInfoKey == NULL) - *duration = 0.3; - else - [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:duration]; -} - -- (void) keyboardWillShow:(NSNotification *)notification { - CGRect bounds; - CGPoint center; - [[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&bounds]; - [[[notification userInfo] objectForKey:UIKeyboardCenterEndUserInfoKey] getValue:¢er]; - - NSTimeInterval duration; - UIViewAnimationCurve curve; - [self getKeyboardCurve:&curve duration:&duration forNotification:notification]; - - CGRect kbframe = CGRectMake(round(center.x - bounds.size.width / 2.0), round(center.y - bounds.size.height / 2.0), bounds.size.width, bounds.size.height); - UIViewController *base = self; - while ([base parentViewController] != nil) - base = [base parentViewController]; - CGRect viewframe = [[base view] convertRect:[list_ frame] fromView:[list_ superview]]; - CGRect intersection = CGRectIntersection(viewframe, kbframe); - - if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4) - intersection.size.height += CYStatusBarHeight(); - - [self resizeForKeyboardBounds:intersection duration:duration curve:curve]; -} - -- (void) keyboardWillHide:(NSNotification *)notification { - NSTimeInterval duration; - UIViewAnimationCurve curve; - [self getKeyboardCurve:&curve duration:&duration forNotification:notification]; - - [self resizeForKeyboardBounds:CGRectZero duration:duration curve:curve]; -} - -- (void) viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - - [self resizeForKeyboardBounds:CGRectZero]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; -} - -- (void) viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - - [self resizeForKeyboardBounds:CGRectZero]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; -} - - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self deselectWithAnimation:animated];