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.
|