swift – 简单的tvOS UIButton无效

swift – 简单的tvOS UIButton无效,第1张

概述我正在尝试实现一个简单的UIButton(tvOS& Swift),但TouchDown事件没有触发. (也试过TouchUpInside). >在模拟器中,我可以直观地看到按下按钮. 我的ViewController.swift代码是: import UIKitclass ViewController: UIViewController { override func viewDi 我正在尝试实现一个简单的UIbutton(tvOS& Swift),但touchDown事件没有触发. (也试过touchUpInsIDe).

>在模拟器中,我可以直观地看到按下按钮.

我的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无效所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1017483.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存