Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-01-2011, 10:14 AM   #20 (permalink)
Moe2392
learning while doing
 
Moe2392's Avatar
 
Join Date: Aug 2011
Location: Ontario
Posts: 31
Moe2392 is on a distinguished road
Default

Quote:
Originally Posted by ghanalupo View Post
I do this to animate the view up and down when the keyboard is required.

In the viewDidLoad method I set up a few observers:

Code:
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
Then the two methods that will be called by the notifications are:

Code:
- (void) keyboardWillShow: (NSNotification*) aNotification;
{	
	
	[UIView beginAnimations:nil context:NULL];
	
		[UIView setAnimationDuration:0.3];
	
		CGRect rect = [[self view] frame];
	
	        rect.origin.y -= 60; 
			
		[[self view] setFrame: rect];
		
	[UIView commitAnimations];
	
}

- (void) keyboardWillHide: (NSNotification*) aNotification;
{
	[UIView beginAnimations:nil context:NULL];
	
		[UIView setAnimationDuration:0.3];
	
		CGRect rect = [[self view] frame];
	
		rect.origin.y += 60; 
		
		[[self view] setFrame: rect];
	
	[UIView commitAnimations];
}
So when a textfield or textview are touched the screen scrolls up automatically as the keyboard comes in from bottom.

However I have a problem!

I have a textfield at the top of the screen that does not require the screen to be scrolled up when keyboard appears but below that I have a textview that does need the screen scrolling up.

I cannot figure out how to check in the methods which control triggered the notification and process accordingly?

I have tried passing the name of the objects in the addObserver calls but the no notifications occur!

Is there a way to query which control is current selected on the screen?

You probably figured this out long ago in your own way, but what i did was i just made if blocks around the code and duplicated it in each statement. So i have two buttons, the first on i say if [UItextfield isFirstResponder]{}
then else if [UItextfield2 isFirstResponder] {//make it animate up and then down}

My problem with this is that when I click on one textfield, then on the other without clicking done on the keyboard, it will not animate up for the first one, then just animate down when i leave the second textfield. Is there a way to just set the screen back to original? I'm actually going to try and make it so that on the animation which moves things back to normal, i just put in the original perameters of the screen (just came up with it as i was typing). So i will set the y back to what it should be to make the screen sit in its place.

//this is what i put in and it moves the screen back to its original place.
//it is not +=, but just = now
rect.origin.y = 0;

Last edited by Moe2392; 09-01-2011 at 10:17 AM. Reason: adding what i did.
Moe2392 is offline   Reply With Quote
 

» Advertisements
» Online Users: 422
13 members and 409 guests
AragornSG, casgali78, dansparrow, EvilElf, freewind, gogoman, juanramoney, pipposanta, QuantumDoja, Sami Gh, smashing, tymex, zulemamn37
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,606
Threads: 94,084
Posts: 402,783
Top Poster: BrianSlick (7,990)
Welcome to our newest member, casgali78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:34 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.