Ios UIKeyboardWillShowNotification调用不会设置UIToolbar的动画
我有一个带有文本字段的Ios UIKeyboardWillShowNotification调用不会设置UIToolbar的动画,ios,uitoolbar,uikeyboard,uianimation,Ios,Uitoolbar,Uikeyboard,Uianimation,我有一个带有文本字段的UIToolbar,当显示键盘时,文本字段应该向上移动 在我的视图中将出现,我注册我的观察者: NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil) (查看将删除我的观察者) 以及功能: func keyboardWillShow(notification
UIToolbar
,当显示键盘时,文本字段应该向上移动
在我的视图中将出现
,我注册我的观察者:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
(查看将删除我的观察者)
以及功能:
func keyboardWillShow(notification: NSNotification) {
println("will show")
let userInfo = notification.userInfo!
let keyboardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue()
let animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as NSNumber).doubleValue
let animations: () -> () = {
self.toolBar.frame.origin.y = self.view.frame.size.height - keyboardFrame.height - self.toolBar.frame.height
}
if animationDuration > 0 {
let options = UIViewAnimationOptions(UInt((userInfo[UIKeyboardAnimationCurveUserInfoKey] as NSNumber).integerValue << 16)) // http://stackoverflow.com/a/18873820/242933
UIView.animateWithDuration(animationDuration, delay: 0, options: options, animations: animations, completion: nil)
} else {
animations()
}
}
func键盘将显示(通知:NSNotification){
println(“将显示”)
让userInfo=notification.userInfo!
让keyboardFrame=(userInfo[UIKeyboardFrameEndUserInfoKey]作为NSValue.CGRectValue()
让animationDuration=(userInfo[UIKeyboardAnimationDurationUserInfoKey]作为NSNumber)。doubleValue
让动画:()->()={
self.toolBar.frame.origin.y=self.view.frame.size.height-keyboardFrame.height-self.toolBar.frame.height
}
如果animationDuration>0{
让options=uiviewmanimationoptions(UInt((userInfo[UIKeyboardAnimationCurveUserInfoKey]作为NSNumber)。integerValue我找到了适合我的答案
let animations: () -> () = {
if !(self.tableView.tracking || self.tableView.decelerating) {
// Move content with keyboard
if overflow > 0 { // scrollable before
self.tableView.contentOffset.y += insetChange
if self.tableView.contentOffset.y < -insetOld.top {
self.tableView.contentOffset.y = -insetOld.top
}
} else if insetChange > -overflow { // scrollable after
self.tableView.contentOffset.y += insetChange + overflow
}
}
}
let动画:()->()={
if!(self.tableView.tracking | | self.tableView.减速){
//使用键盘移动内容
如果溢出>0{//之前可滚动
self.tableView.contentOffset.y+=insetChange
如果self.tableView.contentOffset.y<-insetled.top{
self.tableView.contentOffset.y=-insetled.top
}
}否则如果插入更改>-溢出{//可在之后滚动
self.tableView.contentOffset.y+=插入更改+溢出
}
}
}