Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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 UIView动画不在键盘内工作WillShowNotification事件_Ios_Swift_Uiview_Notificationcenter - Fatal编程技术网

Ios UIView动画不在键盘内工作WillShowNotification事件

Ios UIView动画不在键盘内工作WillShowNotification事件,ios,swift,uiview,notificationcenter,Ios,Swift,Uiview,Notificationcenter,我试图在键盘显示/隐藏期间为视图设置动画,但它不起作用,动画使用的是键盘动画持续时间,而不是我的 我在这里发现这是正常的,因为键盘有一个由运行时提供的动画块。但是,它可以被以下选项覆盖: 但是,它不工作,它忽略了我的配置,而是使用键盘。。我试着用Dispatch.main.async来包装代码,有时可以,有时不能 有人知道怎么修吗 我想这可能是因为我的约束在键盘块内被更新了,而且因为它有自己的动画块,所以当我的自定义动画运行时,它可能已经被更新了,不确定它是否有意义 @objc func

我试图在键盘显示/隐藏期间为视图设置动画,但它不起作用,动画使用的是键盘动画持续时间,而不是我的

我在这里发现这是正常的,因为键盘有一个由运行时提供的动画块。但是,它可以被以下选项覆盖:

但是,它不工作,它忽略了我的配置,而是使用键盘。。我试着用Dispatch.main.async来包装代码,有时可以,有时不能

有人知道怎么修吗

我想这可能是因为我的约束在键盘块内被更新了,而且因为它有自己的动画块,所以当我的自定义动画运行时,它可能已经被更新了,不确定它是否有意义

    @objc func keyboardWillShow(notification: NSNotification) {

         if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {


            constraint.constant = -300

            DispatchQueue.main.sync {
                 UIView.animate(withDuration: 15, delay: 0, options: [.overrideInheritedDuration], animations: {
                               self.view.layoutIfNeeded()
                           }, completion: nil)
            }


        }

    }

UIView.animate是异步任务,因此不需要使用Dispatch Async:) 我不知道如何检测键盘的出现或消失,我认为这是一个问题 以我的方式,它工作得非常完美! 这是我的代码:

@objc func keyboardWillAppear() {
self.constraint.constant -= 100
UIView.animate(withDuration: 2, delay: 0, options: [.overrideInheritedDuration], animations: {
  self.view.layoutIfNeeded()
}) { _ in }
}

}


UIView.animate是异步任务,因此不需要使用Dispatch Async:) 我不知道如何检测键盘的出现或消失,我认为这是一个问题 以我的方式,它工作得非常完美! 这是我的代码:

@objc func keyboardWillAppear() {
self.constraint.constant -= 100
UIView.animate(withDuration: 2, delay: 0, options: [.overrideInheritedDuration], animations: {
  self.view.layoutIfNeeded()
}) { _ in }
}

}