I have TextField1 and TextField2
I would like to scroll a scrolling View only when Keyboard is shown due to TextField2.
This is my actual code.
Is there any solution?
-(void) viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
}
-(void) keyboardDidShow:(NSNotification *) notification {
self.ScrollView.center = CGPointMake(self.originalCenter.x,
self.originalCenter.y-100);
}
-(void) keyboardDidHide:(NSNotification *) notification {
self.ScrollView.center = CGPointMake(self.originalCenter.x,
self.originalCenter.y);
}
You’ll need to listen for the
UITextfielddelegate methods:Just customize the methods to your needs.
If it needs to be exactly when the keyboard shows, you can have a bool to check: