简体   繁体   中英

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

- (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

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

here

#define View_Move_Hight 170 

is defined before @implementation .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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