简体   繁体   English

在屏幕顶部显示文本字段的键盘

[英]show the keyboard of a textfield on top of the screen

在我的iPhone应用程序中,我的问题是我在屏幕底部有一个文本字段,所以当键盘出现时,他隐藏了文本,有一种方法可以在屏幕顶部显示键盘?

You should move your view when the keyboard appears. 键盘出现时应移动视图。 The code is: 代码是:

In .m file 在.m文件中

- (void) loginViewUp : (UIView*) view
{   
    if(!alreadyViewUp)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        CGRect rect = view.frame;
        rect.origin.y -= View_Move_Hight;
        view.frame = rect;
        [UIView commitAnimations];
        alreadyViewUp = !alreadyViewUp;
    }
}

- (void) loginViewDown :(UIView*) view
{        
    if(alreadyViewUp)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        CGRect rect = view.frame;
        rect.origin.y += View_Move_Hight;
        view.frame = rect;
        [UIView commitAnimations];
        alreadyViewUp = !alreadyViewUp;
    }
}

In .h file 在.h文件中

- (void) loginViewUp : (UIView*) view;

here 这里

#define View_Move_Hight 170 

is defined before @implementation . @implementation之前@implementation

你应该设计你的视图,以便它通过键盘向上移动,iPhone用户习惯于键盘总是在屏幕的底部,所以这将违背HIG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM