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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-13-2011, 06:24 AM   #1 (permalink)
Registered Member
 
TrueScot's Avatar
 
Join Date: Oct 2009
Posts: 48
TrueScot is on a distinguished road
Default Scrolling textView above keyboard and back issue

I am able to scroll the textfield (or the frame) above and out of the way whilst the keyboard is displayed, used and dismissed. This works fine for however many times I need it. Inside one controller that is. Whenever I go to a different controller then back to the controller to get input again the scrolling will only ever go up and doesn't come down again despite using the exact same code (ex Apple incidentally).

Is there something I need to reset, release or what before I do this again? Here is the code -

-(void)viewWillAppear:(BOOL)animated {

[[NSNotificationCenter defaultCenter]
addObserver :self
selector :@selector(keyboardWillShow:)
name :UIKeyboardWillShowNotification
object :self.view.window];
[super viewWillAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated{

[[NSNotificationCenter defaultCenter]
removeObserver :self
name :UIKeyboardWillShowNotification object:nil];
[super viewWillDisappear:animated];
}

pragma GCC diagnostic ignored "-Wdeprecated-declarations"

//------------------------------------------------- SHOW KEYBOARD -(void)keyboardWillShow:(NSNotification *)notif {

NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
float bottomPoint = (projectName.frame.origin.y+projectName.frame.size .height+10);
scrollAmount = keyboardSize.height - (self.view.frame.size.height - bottomPoint);
if (scrollAmount > 0) {
moveViewUp = YES;
[self scrollTheView:YES];
} else {
moveViewUp = NO;
}
}

//---------------------------------------------------- SCROLL VIEW UP or DOWN DEPENDING ON VALUE OF 'movedUp' -(void)scrollTheView:(BOOL)movedUp{

[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; CGRect rect = self.view.frame; if (movedUp) { // YES - Move the screen up rect.origin.y -= scrollAmount;
} else { // NO - Move the screen down rect.origin.y += scrollAmount;
} self.view.frame = rect; [UIView commitAnimations]; }

//------------------------------------------------- HIDE KEYBOARD //
-(IBAction)hideKeyBoard:(id) sender {

extern NSMutableArray *gProjects;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:gProjects forKey:@"gProjectsKey"];
[defaults synchronize];
[projectName resignFirstResponder];
if (moveViewUp) {
[self scrollTheView:NO];
}
[self processProject];
}

Last edited by TrueScot; 03-13-2011 at 06:28 AM.
TrueScot is offline   Reply With Quote
Old 03-14-2011, 09:38 AM   #2 (permalink)
Registered Member
 
TrueScot's Avatar
 
Join Date: Oct 2009
Posts: 48
TrueScot is on a distinguished road
Default

Changed moveViewUp and scrollAmount to Globals. The problem went away and the views scroll up and down always now.
TrueScot is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 365
8 members and 357 guests
Absentia, akphyo, apatsufas, BinHex, fredidf, Kirkout, MarkC, mottdog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0