Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void) keyboardWillShow: (NSNotification*)notification
- {
- [self moveControls:notification up:YES];
- }
- -(void) keyboardWillHide: (NSNotification*)notification
- {
- [self moveControls:notification up:NO];
- }
- -(void) moveControls:(NSNotification*)notification up:(BOOL)up
- {
- NSDictionary* userInfo = [notification userInfo];
- CGRect newFrame = [self getNewControlFrame:userInfo up:up];
- [self animateControls:userInfo withFrame:newFrame];
- }
- -(CGRect)getNewControlFrame:(NSDictionary*)userInfo up:(BOOL)up
- {
- CGRect kbFrame = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
- kbFrame = [self.view convertRect:kbFrame fromView:nil];
- CGRect newFrame = self.scrollView.frame;
- newFrame.origin.y += kbFrame.size.height * (up ? -1 : 1);
- return newFrame;
- }
- -(void)animateControls:(NSDictionary*)userInfo withFrame:(CGRect)newFrame
- {
- NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
- UIViewAnimationCurve animationCurve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
- [UIView animateWithDuration:duration
- delay:0
- options:animationOptionsWithCurve(animationCurve)
- animations:^{
- self.scrollView.frame = newFrame;
- }
- completion:^(BOOL finished) {}
- ];
- }
- static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCurve curve)
- {
- return (UIViewAnimationOptions) curve << 16;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement