Help - Search - Members - Calendar
Full Version: need iphone dev help
InsanelyMac Forum > Apple World > Mac Programming and Development
sbrady19
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
Combat
Go and download all the iPhone example apps from developer.apple.com. There's one that shows how to do this.
ipoco
You can use resignFirstResponder http://developer.apple.com/DOCUMENTATION/C...nFirstResponder

CODE
[textField resignFirstResponder];



iPoco
Klutsh
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:
CODE
static const CGFloat FKEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat FPORTRAIT_KEYBOARD_HEIGHT = 216;


Then in your “ViewController.m” place 2 voids:
CODE
- (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
CODE
- (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
stroke
You should really be using macros for stuff like that, not constants.
Klutsh
QUOTE (stroke @ Apr 20 2009, 07:00 PM) *
You should really be using macros for stuff like that, not constants.

Would you mind providing an example?
I'm just starting out too. smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.