Rotating UIButton

后端 未结 4 1052
攒了一身酷
攒了一身酷 2021-01-20 11:33

I\'ve been trying to rotate a button using the following method:

-(IBAction)rotate:(id)sender{
    CGPoint pencilCenter = pencil.center;
    [pencil setCente         


        
4条回答
  •  走了就别回头了
    2021-01-20 12:14

    While it didn't perfectly answer the question, Shardul's answer is great to rotate the button (2 full rotations). So here it is, converted to Swift 3:

    let fullRotation = CABasicAnimation(keyPath: "transform.rotation")
    fullRotation.delegate = self
    fullRotation.fromValue = NSNumber(floatLiteral: 0)
    fullRotation.toValue = NSNumber(floatLiteral: Double(CGFloat.pi * 2))
    fullRotation.duration = 0.5
    fullRotation.repeatCount = 2
    button.layer.add(fullRotation, forKey: "360")
    

    You will need to import QuartzCore:

    import QuartzCore
    

    And your ViewController needs to conform to CAAnimationDelegate:

    class ViewController: UIViewController, CAAnimationDelegate {
    
    }
    

提交回复
热议问题