Jump to content

need iphone dev help


7 posts in this topic

Recommended Posts

I have an idea for an iphone app. I am pretty good with Applescript and Xcode. iPhone is totally GREEK to me. I have many questions but will ask them one at a time until I get the 1st one answered.

 

Qu 1 is very basic.

 

1. I am using the iPhone Utility template, so there is an "i" you click to flip the screen. My interface has text boxes. OK you know what is coming next...............remember to be super specific in your explanation.

 

HOW DO YOU GET THE KEYBOARD TO GO AWAY AFTER YOU ENTER YOUR TEXT.

 

shawn

Link to comment
Share on other sites

If you have ever used a UITextField on the iPhone and seen the screen ’slide’ up to keep the UITextField in view, well here is how I’ve done it.

(This is for Portrait orientation only)

 

In your “ViewController.h” place 2 constants:

static const CGFloat FKEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat FPORTRAIT_KEYBOARD_HEIGHT = 216;

 

Then in your “ViewController.m” place 2 voids:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
animatedDistance = floor(textFieldRect.origin.y - FPORTRAIT_KEYBOARD_HEIGHT);
if( animatedDistance > 0){
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:FKEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
}else{
animatedDistance = 0;
}
[UIView commitAnimations];
}

and

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

 

Then in interface builder set each UITextField’s delegate to “File’s Owner”.

 

The textFieldShouldReturn make the keyboard close, the other handles shifting 'up' to display to keep the textfield in view while your typing

Link to comment
Share on other sites

  • 1 year later...

I created an action called backgroundTap that resigns firstresponder to my UITextFields. Then connected it up to the view. So once you've finished entering numbers via the number pad you can tap anywhere else on the screen, or in another control and the number pad disappears. For the keyboard you can do the same kind of thing when you click the done button.

 

-(IBAction)backgroundTap:(id)sender {

[peopleCount resignFirstResponder];

[billTotal resignFirstResponder];

}

Link to comment
Share on other sites

 Share

×
×
  • Create New...