How can I get strokes using tvOS?

How can I get strokes using tvOS with a simulator? We need to know the touch position. UIPress - no!

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event { // Never called } -(void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(nullable UIPressesEvent *)event { // Works fine! } 
+8
objective-c tvos
source share
4 answers

Presses are associated with physical buttons, such as the Menu button. Pressing starts when you start holding such a button, and ends when you stop pressing a button. There is nothing to do with the touch screen.

Touching in tvOS is similar to touching in iOS, but there is one important difference: they are "indirect" touches, i.e. there is no physical connection between the location of the finger and the location on the screen.

When the touch starts, it will be delivered to the focused image, and the touch will be considered started in the center of this view, regardless of the absolute position of the finger on the touch surface. As the touch approaches, its corresponding position will be updated accordingly.

I do not know a single API that would allow you to determine the absolute position of the finger on the touch surface.

In your case, for your respondent to focus his eyes, he must receive touch events.

+10
source share

I think it should be pressed by Began, not touched by Began.

 (void)pressesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event 
+1
source share

Remember that tvOS has no concept of β€œtouch,” like touching a screen.

The official way to handle "taps" is to use the UITapGestureRecognizer. And this will be when the user presses / presses on the remote computer when the item is in focus state.

This is how I work with UICollectionView:

 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MovieCell", forIndexPath: indexPath) as? MovieCell { let movie = movies[indexPath.row] cell.configureCell(movie) if cell.gestureRecognizers?.count == nil { let tap = UITapGestureRecognizer(target: self, action: "tapped:") tap.allowedPressTypes = [NSNumber(integer: UIPressType.Select.rawValue)] cell.addGestureRecognizer(tap) } return cell } else { return MovieCell() } } func tapped(gesture: UITapGestureRecognizer) { if let cell = gesture.view as? MovieCell { //Load the next view controller and pass in the movie print("Tap detected...") } } 

You can grab the tap position from the UITapGestureRecognizer, which is passed to the handler function.

Also see this Apple TV tutorial: https://www.youtube.com/watch?v=XmLdEcq-QNI

0
source share

A simple way to do this:

 var tapGestureRecognizer: UITapGestureRecognizer! override func didMoveToView(view: SKView) { tapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: Selector("tapped:")) self.view?.addGestureRecognizer(tapGestureRecognizer) } func tapped(sender: UITapGestureRecognizer) { // do something } 

Take a look at my repository: https://github.com/fredericdnddev/tvOS-UITapGestureRecognizer/blob/master/tvOS%20Game/GameScene.swift

0
source share

All Articles