由于我的项目升级为SWIFT 3我的自动布局约束动画不能正常工作;更具体的,他们捕捉到新的位置,而不是动画。
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有这个问题了。
确切的说,只要你想动画视图,你居然叫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
// ....
})
看来,在过去他们一直宽松些能只是重新布局要设置动画的视图。但它认为你应该在上海华被调用layoutIfNeeded的文件中。
升级到3.0 SWIFT
为向左动画像苹果默认的普通动画查看权
//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)
首先为您的约束的新值,然后调用动画。
self.YOUR_CONSTRAINT.constant = NEW_VALUE
UIView.animate(withDuration: 1.0) {
self.view.layoutIfNeeded()
}
雨燕3.1的Xcode 8.3.2
此代码的工作很适合我。在您的视图的任何更改将在慢动作动画。
UIView.animate(withDuration: 3.0, animations: { // 3.0 are the seconds
// Write your code here for e.g. Increasing any Subviews height.
self.view.layoutIfNeeded()
})
迅速4时,Xcode 10
有权搜索向左动画
//初始设置X =您的看法宽度
viewOfSearch.frame = CGRect(x: viewOfSearch.frame.size.width, y: 0 , width: viewOfSearch.frame.size.width, height: 50)
UIView.animate(withDuration: 0.50, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: [], animations: {
//Set x position what ever you want
self.viewOfSearch.frame = CGRect(x: 0, y: 0 , width: self.viewOfSearch.frame.size.width, height: 50)
}, completion: nil)
func setView(view: UIView) {
UIView.transition(with: view, duration: 1.0, options: .transitionFlipFromTop, animations: {
})
}