Swift - Continuous background animation loop

2019-08-15 20:47发布

问题:

Can someone point me in the direction of how i'd go about making a endless loop animation of a UIimageviews alpha property. From the 0 - 1, 1 - 0. I'm fairly new to iOS and programming in general so this may sound dumb. How would I accomplish this without putting the entire app in an endless loop.

回答1:

Continuous animation I don't think this is a good practice in mobile applications, maybe myself wrong. Anyways you can try something like below

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    self.customView.backgroundColor = UIColor(red: 0.0, green: 255.0 , blue: 255.0, alpha: 1.0)
    dispatch_async(dispatch_get_main_queue(), {
        self.performAnimation()

    })

}

func performAnimation() {

    UIView.animateWithDuration(2.0, delay: 0.5, options: .CurveEaseOut | .Repeat | .Autoreverse, animations: {
        self.customView.alpha = 0.0
        }, completion: nil)

}

Where customView is my UIView, you can create your UIImageView similarly.



标签: ios swift uiview