gpt4 book ai didi

device-orientation - 如何横向使用 Apple TV Remote?

转载 作者:行者123 更新时间:2023-12-01 13:56:30 24 4
gpt4 key购买 nike

是否有 tvOS API 来检测横向和/或允许使用 Apple TV Controller 在横向握住 Controller 的情况下进行触摸手势输入? (例如,因此无论 Controller 是纵向还是侧身,应用程序都会获得相对于地板/重力的向上滑动事件)。

最佳答案

我玩过 AppleTV 和 Remote 。可以在 Remote 上进行手势识别。我从我的 Blog article 中复制了示例代码关于这个。

用于检测 Remote 的方向 this answer from the Apple Developer forum might be helpful.

import SpriteKit

class GameScene: SKScene {

let sprite = SKSpriteNode(imageNamed:"Spaceship")

override func didMoveToView(view: SKView) {

/* Setup your scene here */

// Add Sprite
sprite.xScale = 0.5
sprite.yScale = 0.5
sprite.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
self.addChild(sprite)

// Register Swipe Events
let swipeRight:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedRight:"))
swipeRight.direction = .Right
view.addGestureRecognizer(swipeRight)


let swipeLeft:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedLeft:"))
swipeLeft.direction = .Left
view.addGestureRecognizer(swipeLeft)


let swipeUp:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedUp:"))
swipeUp.direction = .Up
view.addGestureRecognizer(swipeUp)


let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedDown:"))
swipeDown.direction = .Down
view.addGestureRecognizer(swipeDown)

}

// Handle Swipe Events
func swipedRight(sender:UISwipeGestureRecognizer){
sprite.position = CGPoint(x: sprite.position.x + 10, y: sprite.position.y)
}

func swipedLeft(sender:UISwipeGestureRecognizer){
sprite.position = CGPoint(x: sprite.position.x - 10, y: sprite.position.y)
}

func swipedUp(sender:UISwipeGestureRecognizer){
sprite.position = CGPoint(x: sprite.position.x, y: sprite.position.y+10)
}

func swipedDown(sender:UISwipeGestureRecognizer){
sprite.position = CGPoint(x: sprite.position.x, y: sprite.position.y-10)
}


override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}

关于device-orientation - 如何横向使用 Apple TV Remote?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32772730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com