Sea*_*159 1 animation constraints ios swift ios10
从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?()
})
}
}
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么它没有动画?
Aar*_*ron 11
在你的动画块你调用self.layoutIfNeeded()其中self的实例UIView是要动画.调用layoutIfNeeded()重绘该方法被调用的视图以及所有子视图.在您的情况下,您不想重绘UIView,您想重绘视图的超级视图.
如果在视图控制器中调用它们,那么你的函数会有意义并且正常工作,但是因为它们是在UIView自身的扩展中调用的,所以你需要调用类似的函数view.superview?.layoutIfNeeded()
| 归档时间: |
|
| 查看次数: |
2567 次 |
| 最近记录: |