class newVC:UIViewController{
let l = UILabel()
var timer: Timer!
var index = 0
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "?", style: .plain, target: self, action:#selector(clickButton(_:)))
self.view.backgroundColor = UIColor.green
l.frame = CGRect(x: 30.0, y: 140.0, width: 100.0, height: 100.0)
l.backgroundColor = UIColor.green
self.view.addSubview(l)
let lab = UIButton(type: .custom)
lab.frame = CGRect(x: 30.0, y: 100.0, width: 30.0, height: 30.0)
lab.backgroundColor = UIColor.green
lab.addTarget(self, action: #selector(clickButton(_:)), for: .touchUpInside)
self.view.addSubview(lab)
UIView.animate(withDuration: 3, delay: 1, options: .transitionFlipFromTop, animations:{
let arr = ["是","无","情","物","千","山","鸟","飞","绝","落","红","不"]
let count = 12
let center = CGPoint(x:Double(self.view.frame.width/2),y:Double(self.view.frame.height/2))
let radius = min(self.view.frame.width/3.0, self.view.frame.height/4.0)
for i in 0..<12{
let lab = UIButton(type: .custom)
lab.backgroundColor = UIColor.white
lab.bounds = CGRect(x: 30.0, y: 100.0, width: 30.0, height: 30.0)
let angle = 2*CGFloat(M_PI)*CGFloat(i)/CGFloat(count)
lab.setTitle(arr[i], for: .normal)
//lab.addTarget(self, action: #selector(self.cloor(_:)), for: .touchUpInside)
lab.tag = i + 10
lab.setTitleColor(UIColor.red, for: .normal)
lab.titleLabel?.font = UIFont.systemFont(ofSize: 15)
lab.center = CGPoint(x: center.x + radius*cos(angle), y: center.y + radius*sin(angle))
self.view.addSubview(lab)
}
}
, completion:{(finished:Bool) -> Void in
UIView.animate(withDuration: 1, animations:{ () -> Void in
if self.timer == nil{
self.timer = Timer.scheduledTimer(timeInterval: 0.2,
target:self,selector:#selector(self.tickDown),
userInfo:nil,repeats:true)
}
})
}
)
// Do any additional setup after loading the view.
}
deinit {
timer.invalidate()
}
func tickDown(){
if index < 12{
index += 1
}else{
index = 1
}
for i in 10..<22{
let b = self.view.viewWithTag(i) as! UIButton
b.bounds = CGRect(x: 30.0, y: 100.0, width: 30.0, height: 30.0)
b.titleLabel?.font = UIFont.systemFont(ofSize: 15)
b.setTitleColor(UIColor.red, for: .normal)
b.backgroundColor = UIColor.white
}
let b = self.view.viewWithTag(index + 9) as! UIButton
b.bounds = CGRect(x: 30.0, y: 100.0, width: 40.0, height: 40.0)
b.titleLabel?.font = UIFont.systemFont(ofSize: 20)
b.setTitleColor(UIColor.black, for: .normal)
b.backgroundColor = UIColor.yellow
}