简体   繁体   中英

Animate UIView to go up off screen then up off screen from bottom endlessly

My question is similar to this one. However, I want an updated version for swift, and I want it to go endlessly. Here is my animation now:

bubble.frame.origin = CGPoint(x: 75, y: -120)

UIView.animate(
    withDuration: 2.5,
    animations: {
        self.bubble.transform = CGAffineTransform(translationX: 0, y: self.view.frame.height * -1.3)
    }
)

After the bubble goes off screen, I want it to go back on from the bottom and go up off screen again and again endlessly.

Use the option from the UIViewAnimationOptions set:

UIViewAnimationOptions.Repeat

Should look like this with your code:

bubble.frame.origin = CGPoint(x: 75, y: -120)
UIView.animate(withDuration: 2.5, options: [UIViewAnimationOptions.Repeat], animations: {
               self.bubble.transform = CGAffineTransform(translationX: 0, y: self.view.frame.height * -1.3)
               })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM