
是否真的只能使用UIKeyboarDWillChangeFrameNotification的通知,
只是“不打扰”“老”UIKeyboarDWillShowNotification和UIKeyboarDWillHIDeNotification?
测试似乎显示它的工作完美,只使用keyboardFrameDIDChange – 但我们可能会缺少一些东西?
这里是一个如何使用UIKeyboarDWillChangeFrameNotification https://stackoverflow.com/a/26226732/294884的例子
解决方法 这绝对是可能的,可以把你的代码减少一半.以下示例使用自动布局进行大量重载.NSNotificationCenter.defaultCenter().addobserverForname( UIKeyboarDWillChangeFrameNotification,object: nil,queue: nil) { (notification) in var userInfo = notification.userInfo! let frameEnd = userInfo[UIKeyboardFrameEndUserInfoKey]!.CGRectValue let convertedFrameEnd = self.vIEw.convertRect(frameEnd,fromVIEw: nil) let heightOffset = self.vIEw.bounds.size.height - convertedFrameEnd.origin.y self.messageFIEldBottomConstraint.constant = heightOffset let curve = userInfo[UIKeyboardAnimationCurveUserInfoKey]!.unsignedIntValue let options = UIVIEwAnimationoptions(rawValue: UInt(curve) << 16) UIVIEw.animateWithDuration( userInfo[UIKeyboardAnimationDurationUserInfoKey]!.doubleValue,delay: 0,options: options,animations: { self.vIEw.layoutIfNeeded() },completion: nil )} self.messageFIEldBottomConstraint是一个NSLayoutConstraint,它将文本字段的底部绑定到视图的底部.当键盘出现时,此代码使该字段向上移动,当它消失时.
所有这一切都可能在iOS< 8通过使用UIKeyboarDWillShowNotification和UIKeyboarDWillHIDeNotification的组合.但!如您所说,iOS 8引入了可以由用户折叠或展开的QuickType部分.该解决方案将正确地动画文本字段,以使其始终附加到键盘的顶部,无论QuickType是否打开.
总结以上是内存溢出为你收集整理的ios8 – 仅使用UIKeyboardWillChangeFrameNotification通知全部内容,希望文章能够帮你解决ios8 – 仅使用UIKeyboardWillChangeFrameNotification通知所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)