Swift 3 UIViewanimation
由于升级我的项目swift 3我的自动布局约束animation不工作; 更具体的说,他们正在攫取新的职位,而不是animation。
UIView.animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.curveEaseIn, animations: { () -> Void in constraint.constant = ButtonAnimationValues.YPosition.DefaultOut() self.layoutIfNeeded() }, completion: { (finished) -> Void in // .... })
我知道他们添加了UIViewPropertyAnimator
类,但还没有尝试。
我也有这个问题,最新的更新迅速3。
确切地说,每当你想为视图设置animation时,你实际上就是在该视图的超级视图上调用layoutIfNeeded。
试试这个:
UIView.animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.curveEaseIn, animations: { () -> Void in constraint.constant = ButtonAnimationValues.YPosition.DefaultOut() self.superview?.layoutIfNeeded() }, completion: { (finished) -> Void in // .... })
过去,他们似乎已经宽大了,只能重新布置要制作animation的视图。 但它在文档中,你应该真的在superview中调用layoutIfNeeded。
升级到swift 3.0
查看从左到右的animation,如苹果默认推animation
//intially set x = SCREEN_WIDTH view.frame = CGRect(x: ScreenSize.SCREEN_WIDTH, y: ScreenSize.SCREEN_HEIGHT - heightTabBar , width: ScreenSize.SCREEN_WIDTH, height: heightTabBar) UIView.animate(withDuration: 0.50, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: [], animations: { //Set x position what ever you want view.frame = CGRect(x: 0, y: ScreenSize.SCREEN_HEIGHT - heightTabBar , width: ScreenSize.SCREEN_WIDTH, height: heightTabBar) }, completion: nil)
首先为你的约束设置新的值,然后调用animation。
self.YOUR_CONSTRAINT.constant = NEW_VALUE UIView.animate(withDuration: 1.0) { self.view.layoutIfNeeded() }
Swift 3.1,Xcode 8.3.2
这段代码适合我。 视图上的任何更改都将以慢动作生animation面。
UIView.animate(withDuration: 3.0, animations: { // 3.0 are the seconds // Write your code here for eg Increasing any Subviews height. self.view.layoutIfNeeded() })