我想在我的应用程序的表单中添加一个按钮,无论滚动如何,该按钮都会粘在 View 的底部。我该如何实现这个功能?
您将不得不使该 View 成为主 ViewController View 的直接 subview ,并将其放置在 View 的底部。这可以按照您希望的任何方式完成。然后,当键盘显示或隐藏时,要将其“粘合”到 View 底部,您将不得不在 中监听
。当这些事件触发时,您可以模仿动画持续时间和缓动方法,并按照 willshow 和 willhide 函数中给定的数量上下移动底部 View 。像这样的:UIKeyboardWillShowNotification
和 UIKeyboardWillHideNotification
NSNotificationCenter
- (void)keyboardWillShowNSNotification *)aNotification
{
NSDictionary* userInfo = [aNotification userInfo];
// Get animation info from userInfo
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
//Do whatever you would like to here, likely move your bottom view
[UIView commitAnimations];
}
关于ios - View 下方和键盘顶部的粘滞按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38508026/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |