If it is OK visually, the easiest is to move the entire self.view.frame and then move it back down when finished.
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3f;
- (void) animateForToNewYPosition:(int)newYPosition {
// move for kdb
if (self.view.frame.origin.y == newYPosition) {
return;
}
// start animation
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
// move it
self.view.frame.origin.y = newYPosition;
[UIView commitAnimations];
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…