小编Joh*_*ite的帖子

动画UIView背景颜色迅速

我想用随机颜色动画UIView的背景.这是我到目前为止所做的:

import UIKit

class ViewController: UIViewController {

    var timer = NSTimer()
    var colours = UIColor()

    override func viewDidLoad() {
        super.viewDidLoad()
        getRandomColor()
        timerF()

        UIView.animateWithDuration(2, delay: 0.0, options:[UIViewAnimationOptions.Repeat, UIViewAnimationOptions.Autoreverse], animations: {
            self.view.backgroundColor = self.colours

            }, completion:nil)
    }

    func timerF(){
         timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("getRandomColor"), userInfo: nil, repeats: true)
    }

    func getRandomColor(){
        let red   = Float((arc4random() % 256)) / 255.0
        let green = Float((arc4random() % 256)) / 255.0
        let blue  = Float((arc4random() % 256)) / 255.0
        let alpha = Float(1.0)
        colours …
Run Code Online (Sandbox Code Playgroud)

animation colors uiview ios swift

16
推荐指数
1
解决办法
2万
查看次数

标签 统计

animation ×1

colors ×1

ios ×1

swift ×1

uiview ×1