如何使用tvOS接收触摸? [英] How can I receive touches using tvOS?

查看:93
本文介绍了如何使用tvOS接收触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在模拟器上使用tvOS接收触摸?我们需要知道触摸位置. UIPress-不用了!

How can I receive touches using tvOS with the simulator? We need know touch position. UIPress - have no it!

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event {
    // Never called
}

-(void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(nullable UIPressesEvent *)event {
    // Works fine!
}

推荐答案

按下与物理按钮(如菜单"按钮)相关.当您开始按住此类按钮时,便会开始按下,而当您停止按住该按钮时,便会结束.没有与印刷机相关的相对屏幕位置.

Presses are related to physical buttons, like the Menu button. A press begins when you start holding down such a button, and it ends when you stop holding down the button. There isn't any screen-relative position associated with a press.

tvOS中的触摸与iOS中的触摸类似,但是有一个重要的区别:它们是间接"触摸,即手指的位置与屏幕上的位置之间没有物理关系.

Touches in tvOS are similar to touches in iOS, but there's one important difference: they're "indirect" touches, i.e. there isn't a physical relationship between the location of the finger and a location on screen.

当触摸开始时,它将被传递到聚焦视图,并且无论手指在触摸表面上的绝对位置如何,触摸都将被视为从该视图的中心开始.随着触摸的移动,其屏幕相对位置将相应更新.

When a touches begins, it will be delivered to the focused view, and the touch will be considered to have started in the center of that view, regardless of the absolute position of the finger on the touch surface. As the touch moves, its screen-relative position will be updated accordingly.

我不知道有任何API可以让您确定手指在触摸表面上的绝对位置.

I'm not aware of any API that would allow you to determine the absolute position of a finger on the touch surface.

以您为例,使响应者成为重点关注的视图应该使它接收触摸事件.

In your case, making your responder the focused view should cause it to receive touch events.

这篇关于如何使用tvOS接收触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆