Blocks on Swift (animateWithDuration:animations:completion:)

前端 未结 7 1828
梦如初夏
梦如初夏 2020-12-02 12:08

I\'m having trouble making the blocks work on Swift. Here\'s an example that worked (without completion block):

UIView.animateWithDuration(0.07) {
    self.so         


        
7条回答
  •  隐瞒了意图╮
    2020-12-02 12:30

    There is my solution above based on accepted answer above. It fades out a view and hiddes it once almost invisible.

    Swift 2

    func animateOut(view:UIView) {
    
        UIView.animateWithDuration (0.25, delay: 0.0, options: UIViewAnimationOptions.CurveLinear ,animations: {
            view.layer.opacity = 0.1
            }, completion: { _ in
                view.hidden = true
        })   
    }
    

    Swift 3, 4, 5

    func animateOut(view: UIView) {
    
        UIView.animate(withDuration: 0.25, delay: 0.0, options: UIView.AnimationOptions.curveLinear ,animations: {
            view.layer.opacity = 0.1
        }, completion: { _ in
            view.isHidden = true
        })
    }
    

提交回复
热议问题