Blocks on Swift (animateWithDuration:animations:completion:)

前端 未结 7 1833
梦如初夏
梦如初夏 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:16

    Sometimes you want to throw this in a variable to animate in different ways depending on the situation. For that you need

     let completionBlock : (Bool) -> () = { _ in 
     }
    

    Or you could use the equally verbose:

     let completionBlock = { (_:Bool) in 
     }
    

    But in any case, you have have to indicate the Bool somewhere.

提交回复
热议问题