【发布时间】:2017-10-19 18:31:58
【问题描述】:
我面临着非常奇怪的情况。当键盘出现在某些 UITextView 上时,我想向上滚动 UIScrollView 以使其可见,并且这部分代码工作正常。但是当键盘消失时,scrollView 并没有回到原来的位置。当我拖动它时,它会回到原来的位置。以下是我所做的。请指导我错过了什么
- (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) {
}];
}
【问题讨论】:
标签: ios objective-c uiscrollview