非常に奇妙な状況に直面しています。 UITextViewにキーボードが現れたときにUIScrollViewをスクロールアップしてコードのこの部分がうまくいきたいと思っています。しかし、キーボードが消えると、scrollViewは元の位置に来ません。私はそれをドラッグすると、それは元の位置に来る。私がしたことは次のとおりです。私はキーボードが消えたときにUIScrollViewが元の位置にスクロールしない
- (void)keyboardWillHide:(NSNotification *)notification {
NSDictionary* info = [notification userInfo];
kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect commentViewFrame = self.detailCommentView.frame;
commentViewFrame.origin.y += kbSize.height;
[UIView animateWithDuration:0.3 animations:^{
[self.detailCommentView setFrame:commentViewFrame];
self.scrollView.contentOffset = CGPointMake(0, self.detailCommentView.frame.origin.y - 90);
} completion:^(BOOL finished) {
}];
}
- (void)keyboardWillShow:(NSNotification *)notification {
NSDictionary* info = [notification userInfo];
kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect commentViewFrame = self.detailCommentView.frame;
commentViewFrame.origin.y -= kbSize.height;
[UIView animateWithDuration:0.3 animations:^{
[self.detailCommentView setFrame:commentViewFrame];
self.scrollView.contentOffset = CGPointMake(0, self.detailCommentView.frame.origin.y + 90);
} completion:^(BOOL finished) {
}];
}
私のミス、正しいものはself.detailCommentView.frame.origin.yです。私はそれを今編集し、返信にも感謝します。それが動作するかどうかをチェックさせてください。 –
解決策の最初の部分を理解できませんでした。いくつかのコードを教えてください。ありがとう –
あなたのコードで 'UIKeyboardFrameBeginUserInfoKey'を' UIKeyboardFrameEndUserInfoKey'に置き換えてみましょう。 – RaffAl