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 03-13-2010, 05:46 AM   #16 (permalink)
teek
Registered Member
 
Join Date: Mar 2010
Location: Norway
Posts: 49
teek 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?

Yeah, NSNotification.object returns the object associated with the notification. So you can simply check if the object is one or more of the fields you dont want to autoscroll for.
teek is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,539
Threads: 94,055
Posts: 402,653
Top Poster: BrianSlick (7,982)
Welcome to our newest member, cecilytw61
Powered by vBadvanced CMPS v3.1.0

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