斯威夫特3的UIView动画

问题描述 投票:16回答:5

由于我的项目升级为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类,但我没有尝试。

ios swift uiview uiviewanimation swift3
5个回答
27
投票

我与最新更新迅速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的文件中。


9
投票

升级到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)

6
投票

首先为您的约束的新值,然后调用动画。

self.YOUR_CONSTRAINT.constant = NEW_VALUE
UIView.animate(withDuration: 1.0) {
    self.view.layoutIfNeeded()
}

2
投票

雨燕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()

})

1
投票

迅速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)

0
投票
func setView(view: UIView) {
        UIView.transition(with: view, duration: 1.0, options: .transitionFlipFromTop, animations: {
        })
    }
  • 更改选项部分,在那个特定的UIView应用新的动画。
© www.soinside.com 2019 - 2024. All rights reserved.