使视图向上滑动为键盘腾出空间? [英] Making the view slide up to make room for the keyboard?

查看:80
本文介绍了使视图向上滑动为键盘腾出空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习编程iPhone应用程序,我似乎不知道如何使视图幻灯片出来的方式当键盘出现(所以你仍然可以看到你正在输入的文本字段)。如何做?

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?

推荐答案

如果视觉上是好的,最简单的是移动整个self.view.frame然后

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

这篇关于使视图向上滑动为键盘腾出空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆