swift 三角函数简单用

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

    

   }

 

转载于:https://www.cnblogs.com/linximu/p/6781226.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值