Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

objective c - How can I receive touches using tvOS?

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!
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...