Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIKeyboardWillShowNotification调用不会设置UIToolbar的动画_Ios_Uitoolbar_Uikeyboard_Uianimation - Fatal编程技术网

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+=插入更改+溢出
}
}
}