自iOS 10以來我注意到動畫布局更改(layoutIfNeeded()
)並非動畫。這是我的UIView擴展,它在iOS 9和更低版本上效果很好。iOS 10中的動畫錯誤
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?()
})
}
}
有誰知道爲什麼它不是動畫?
你也有一個問題,真正的設備? –
@DanLevy是的iPhone 6S的iOS 10.0.1 – SeanRobinson159
你是什麼意思的「不正確的工作」? – Aaron