2 Replies
      Latest reply on Sep 17, 2015 11:29 PM by KumobiusIvan
      KumobiusIvan Level 2 Level 2 (40 points)

        With tvOS how do I get the touch position on the trackpad from a UITouch?

         

        At the moment if I call locationInView: it always starts at (960, 540) and then movements are relative to this position. Is there a way of getting the actual position on the trackpad the user touched?

        • Re: UITouch, get position on trackpad
          iOSAaron Level 2 Level 2 (30 points)

          You can't get the exact position of a touch on the remotes touch surface, how ever you can get the top, bottom, left and right. Think of the current Apple remote it has an up, down, left and right buttons. You can detect touches in the same way.

           

          The below will be triggered when a touch event occurs on the remotes touch surface.

          - (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
          {
              for (UIPress *item in presses)
              {
                  NSLog(@"item = %@", item);
              }
          }
          
          2015-09-18 14:16:10.316 AppName[271:29940] item = <UIPress: 0x13ce18210 phase=0 type=3 force=1.000000>
          
          
          

           

          A UIPress has a few properties on it. The "UIPressType" of a UIPress will tell you which button was pressed on the remote. See below for the types of button presses on the new Apple Remote.

           

          NS_ENUM_AVAILABLE_IOS(9_0) typedef NS_ENUM(NSInteger, UIPressType) {
              UIPressTypeUpArrow,
              UIPressTypeDownArrow,
              UIPressTypeLeftArrow,
              UIPressTypeRightArrow,
              UIPressTypeSelect,
              UIPressTypeMenu,
              UIPressTypePlayPause,
          };
          
          
          
            • Re: UITouch, get position on trackpad
              KumobiusIvan Level 2 Level 2 (40 points)

              Thanks. Are there any plans on adding access to this data?

               

              At the moment we can kind of get the exact position by using the GameController framework with reportsAbsoluteDpadValues = YES on the GCMicroGamepad. We will then get touch coordinates from (-1, -1) to (1, 1). The problem with this is that is returns to (0, 0) when the touch ends.