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 01-10-2010, 09:49 AM   #15 (permalink)
ghanalupo
Registered Member
 
Join Date: Jun 2009
Posts: 133
ghanalupo is on a distinguished road
Default

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?
ghanalupo is offline   Reply With Quote
 

» Advertisements
» Online Users: 474
16 members and 458 guests
Abidullah, Alex40, AngryOrange, ArthurOff, Arty Tales, bignoggins, ilmman, jbro, kamrul00gg, kln, magdaleneei61, Nobbsy, padsoftware, schmallegory, Sloshmonster, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,429
Threads: 94,024
Posts: 402,577
Top Poster: BrianSlick (7,978)
Welcome to our newest member, magdaleneei61
Powered by vBadvanced CMPS v3.1.0

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