Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

iphone - Making the view slide up to make room for the keyboard?

I just started learning to program iPhone apps and I can't seem to figure out how to make the view slide out of the way when the keyboard appears (so you can still see the text field you're typing in). How is it done?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];  
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...