>在模拟器中,我可以直观地看到按下按钮.
我的VIEwController.swift代码是:
import UIKitclass 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") }}
为了检测按钮点击,我需要做什么?
解决方法 您不应该在tvOS上使用“.touchDown”或“.touchUpInsIDe”,因为这不符合您的预期:您可能希望使用“UIControlEvents.PrimaryActionTriggered”.touchUpInsIDe是由实际触摸触发的,实际上并非如此.如果要按遥控器上的“选择”按钮以触发按钮,则应使用PrimaryActionTriggered.
总结以上是内存溢出为你收集整理的swift – 简单的tvOS UIButton无效全部内容,希望文章能够帮你解决swift – 简单的tvOS UIButton无效所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)