ios - 键盘关闭时 ScrollView 不会向下滚动
<p>我在键盘下方的移动内容上使用了苹果指南<br><br> <a href="https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html" rel="noreferrer noopener nofollow">Guide here</a><br><br>当键盘打开时它在向上滚动时效果很好,但是当键盘关闭时它不会向下滚动并且我留下 ScrollView 的顶部被切断。<br><br>我的代码<br><pre><code>// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = ;
CGSize kbSize = [ CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
_myScrollView.contentInset = contentInsets;
_myScrollView.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your app might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
;
}
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
_myScrollView.contentInset = contentInsets;
_myScrollView.scrollIndicatorInsets = contentInsets;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p>这是我在键盘退出时使用的代码。我对你的原始代码有问题,因为它似乎不想在 iOS 7 中工作。<br><pre><code>-(void) keyboardWillHide:(NSNotification *)note
{
// Get the keyboard size
CGRect keyboardBounds;
[ getValue: &keyboardBounds];
CGRect frame = self.scrollView.frame;
;
;
;
//add keyboard size to current scrollview frame
frame.size.height += keyboardBounds.size.height;
//apply frame to scrollview
self.scrollView.frame = frame;
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 键盘关闭时 ScrollView 不会向下滚动,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24666229/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24666229/
</a>
</p>
页:
[1]