苹果tvOS相对触控位置绝对位置

时间:2015-09-23 06:33:03

标签: tvos

当我们接触到触摸时,即使我们按下触摸面板的右下侧,也会触摸触摸面板中心(x 960 y 540)。

我们如何在遥控触控面板上采取绝对按压位置 - 左上角为0 0,右下角为1920 x 1080? 现在我使用此代码进行接收触摸

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

      for(UITouch *touch in touches) {
            CGPoint p = [touch locationInView: view];
            //....            
      }  
}

1 个答案:

答案 0 :(得分:1)

我认为TVOS导航概念是不同的。尝试在遥控器上盲目地击中UI元素并不是用户友好的。

你不能用这样的东西来确定用户想做什么吗?

var touchPositionX: CGFloat = 0.0
var touchPositionY: CGFloat = 0.0
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        let location = touch.locationInNode(self)

        if location.x < touchPositionX && location.y < touchPositionY {
            // TopRight Corner
        }
        // ...
    }
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        // No repositioning
        touchPositionX = touch.locationInNode(self).x
        touchPositionY = touch.locationInNode(self).y
    }
}