我有一個鍵盤通知,我想要它,以便當它停止時,佔位符視圖動畫到搜索欄的左邊緣。UIView動畫無法與NSLayoutConstraint?
下面是我用來調用與鍵盤打開異步的動畫。目前,視圖移動到了我想要的位置,但它好像是在那裏傳送而不是動畫。
DispatchQueue.main.async {
if isKeyboardShowing {
UIView.animate(withDuration: 2, delay: 1, options: UIViewAnimationOptions.curveEaseOut, animations: {
NSLayoutConstraint(item: self.placeholder, attribute: .left, relatedBy: .equal, toItem: self.searchBar, attribute: .left, multiplier: 1, constant: 5).isActive = true
}, completion: { (completed) in
})
}
}
有什麼建議嗎?