ios - View 下方和键盘顶部的粘滞按钮
<p><p>我想在我的应用程序的表单中添加一个按钮,无论滚动如何,该按钮都会粘在 View 的底部。我该如何实现这个功能?</p>
<p> <a href="/image/ceCoc.png" rel="noreferrer noopener nofollow"><img src="/image/ceCoc.png" alt="Button at the bottom of the view"/></a> </p>
<p> <a href="/image/Vbq0u.png" rel="noreferrer noopener nofollow"><img src="/image/Vbq0u.png" alt="Button on top of the keyboard"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您将不得不使该 View 成为主 ViewControllerView 的直接 subview ,并将其放置在 View 的底部。这可以按照您希望的任何方式完成。然后,当键盘显示或隐藏时,要将其“粘合”到 View 底部,您将不得不在 <code> 中监听 <code>UIKeyboardWillShowNotification</code> 和 <code>UIKeyboardWillHideNotification</code> NSNotificationCenter</code>。当这些事件触发时,您可以模仿动画持续时间和缓动方法,并按照 willshow 和 willhide 函数中给定的数量上下移动底部 View 。像这样的:</p>
<pre><code>- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSDictionary* userInfo = ;
// Get animation info from userInfo
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardEndFrame;
[ getValue:&animationCurve];
[ getValue:&animationDuration];
[ getValue:&keyboardEndFrame];
;
;
;
//Do whatever you would like to here, likely move your bottom view
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios -View 下方和键盘顶部的粘滞按钮,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38508026/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38508026/
</a>
</p>
页:
[1]