alex
alex

Reputation: 879

show the keyboard of a textfield on top of the screen

In my iPhone apps, my problem is that I have a textfield at the bottom of the screen, so when the keyboard appear, he hides the textfied, there is a way to show the keyboard on the top of the screen?

Upvotes: 4

Views: 1464

Answers (2)

Arsalan
Arsalan

Reputation: 51

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.

Upvotes: 4

Chris Wagner
Chris Wagner

Reputation: 20993

You should design your view so that it shifts up with the keyboard, iPhone users are used to the keyboard always being on the bottom of the screen so this would go against the HIG

Upvotes: 2

Related Questions