我是新來的斯威夫特,我試圖讓定時器(在標籤),開始與長按按鈕。同時我想在長按按鈕時更改長按按鈕圖像。我離開按鈕,我想讓按鈕恢復。長按識別手勢通過按鈕 - 斯威夫特3
什麼可能是錯誤的?
@IBOutlet weak var myBtn: UIButton!
func initGesture()
{
{ let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longTap(_:)))
myBtn.addGestureRecognizer(longGesture)
}
}
func TimerAction()
{
Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(longTap), userInfo: nil, repeats: false)
myBtn.setImage(UIImage(named: "xxx.png"), for: .normal)
}
@IBOutlet weak var lbl: UILabel!
func start()
{
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: (#selector(ViewController2.updateTime as (ViewController2) ->() ->())), userInfo: nil, repeats: true)
}
func updateTimer() {
count += 1
let hours = Int(count)/3600
let minutes = Int(count)/60 % 60
let seconds = Int(count) % 60
label.text = String(format: "%02i:%02i:%02i",hours,minutes,seconds)
}
func reset()
{
timer.invalidate()
count = 0
label.text = "00:00:00"
}
什麼是你的代碼做exaclt? –
我正在努力做一些我寫的東西。我用長按手勢識別敲了myBtn。我在哪裏錯了? @MohammadBashirSidani – MarryJoe
https://stackoverflow.com/questions/34548263/swift-button-tap-and-long-press-gesture – Eridana