我發現這個代碼可以讓你在Swift中按下按鈕時旋轉/旋轉90度。但是我想要做的是在按下按鈕時無限旋轉/旋轉按鈕,並在再次按下按鈕時停止旋轉。這裏是我的代碼有:無限旋轉按鈕:Swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var otherbutton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Rotate(sender: AnyObject) {
UIView.animateWithDuration(1.0,
animations: ({
self.otherbutton.transform = CGAffineTransformMakeRotation(90)
}))
}
}
我試過這個,但是我收到一條錯誤消息,說CABasicsAnimation沒有名爲'layer'的成員。我在這部分代碼中得到了這個消息:spinButton.layer.addAnimation(spinAnimation,forked:「transform.rotation.z」) –
spinButton.layer應該是一個不是CABasicAnimation的按鈕,因爲你的錯誤狀態 –
我想我只是不'對此我非常瞭解,所以我不確定如何解決這個問題。這是非常新的。我知道一些JavaScript的基礎知識,但這不是很多 –