【发布时间】:2015-12-16 20:12:38
【问题描述】:
我正在尝试实现一个简单的 UIButton(tvOS 和 Swift),但 TouchDown 事件没有触发。 (也尝试过 TouchUpInside)。
- 在模拟器中,我可以直观地看到按钮被按下。
我的 ViewController.swift 代码是:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type: UIButtonType.System)
button.frame = CGRectMake(100, 100, 400, 150)
button.backgroundColor = UIColor.greenColor()
button.setTitle("Test", forState: UIControlState.Normal)
button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchDown)
self.view.addSubview(button)
self.view.userInteractionEnabled = true
}
func buttonAction(sender:UIButton!){
NSLog("Clicked")
}
}
我需要做什么才能检测到按钮点击?
【问题讨论】: