我正在爲我的iOS應用程序創建「登錄」和「創建帳戶」窗體。隱藏時,我成功實現了UITextField的滾動。但是,現在我實現了「下一步」按鈕,因爲鍵盤永遠不會被解僱,因此不會調用「UIKeyboardDidShowNotification」。我需要調用keyboardWasShow方法,以便檢查活動的UITextField是否隱藏。向上滾動UITextField
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your application might not need or want this behavior.
CGRect aRect = self.view.frame;
CGPoint pointInSuperview = [self.view convertPoint:self.activeField.frame.origin fromView:self.scrollView];
aRect.size.height -= kbSize.height;
//added 10 to y axis because tip of origin was outside of keyboard
pointInSuperview.y +=20;
if (!CGRectContainsPoint(aRect, pointInSuperview)) {
CGPoint scrollPoint = CGPointMake(0.0, pointInSuperview.y - (kbSize.height -15));
NSLog(@"it is not in the rect");
[self.scrollView setContentOffset:scrollPoint animated:YES];
}
}
,我有一個觀察者
和我實現我的下一步按鈕後(見下文)keyboardWasShown方法不調用,所以它永遠不會檢查活動的UITextField是隱藏的。
//functionality for next action
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.emailAddress) {
[self.fullName becomeFirstResponder];
[self keyboardWasShown:(NSNotification*)UIKeyboardDidShowNotification];
}
else if (textField == self.fullName) {
[self.password becomeFirstResponder];
}
else if (textField == self.password) {
[self.confirmPassword becomeFirstResponder];
}
[textField resignFirstResponder];
return YES;
}
當用戶點擊下一步按鈕時,調用keyboardWasShown的最佳方法是什麼?我試圖讓它成爲一種公共方法,但是當我嘗試手動調用它時,我不斷收到錯誤。