Начиная с iOS 10 я заметил, что анимация изменения макета ( layoutIfNeeded()
) не является анимацией. Вот мое расширение UIView, которое отлично работает на iOS 9 и ниже.
func slideIn(from edgeConstraint: NSLayoutConstraint, withDuration duration: Double = 0.25, finishedAnimating: (() -> Void)? = nil) {
dispatch_async(dispatch_get_main_queue()) {
edgeConstraint.constant = 0
UIView.animateWithDuration(duration,
delay: 0.0,
options: .BeginFromCurrentState,
animations: { self.layoutIfNeeded() },
completion: { didComplete in
finishedAnimating?()
})
}
}
func slideOut(from edgeConstraint: NSLayoutConstraint, withDuration duration: Double = 0.25, finishedAnimating: (() -> Void)? = nil) {
dispatch_async(dispatch_get_main_queue()) {
edgeConstraint.constant = -self.frame.height
UIView.animateWithDuration(duration,
delay: 0.0,
options: .BeginFromCurrentState,
animations: { self.layoutIfNeeded() },
completion: { didComplete in
finishedAnimating?()
})
}
}
Кто-нибудь знает, почему он не анимируется?