有没有人想出如何使用新的Apple TV遥控器进行动作事件?谢谢.
我试过打电话
override func motionBegan(motion: UIEventSubtype,withEvent event: UIEvent?) {
super.motionBegan(motion,withEvent: event)
print("motion!")
}
override func motionEnded(motion: UIEventSubtype,withEvent event: UIEvent?) {
super.motionEnded(motion,withEvent: event)
print("motion ended!")
}
有和没有电话超级给我什么都没有.
这里有一个很好的例子:
https://forums.developer.apple.com/message/65560#65560
这基本上就是Daniel Storm上面所说的,但是接着这个让它为我工作.这就是我做的.
https://forums.developer.apple.com/message/65560#65560
这基本上就是Daniel Storm上面所说的,但是接着这个让它为我工作.这就是我做的.
在appDelegate中:
var motionDelegate: ReactToMotionEvents? = nil
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let center = NSNotificationCenter.defaultCenter()
center.addobserver(self,selector: "setupControllers:",name: GCControllerDidConnectNotification,object: nil)
center.addobserver(self,name: GCControllerDiddisconnectNotification,object: nil)
GCController.startWirelessControllerdiscoveryWithCompletionHandler { () -> Void in
}
return true
}
func setupControllers(notif: NSNotification) {
print("controller connection")
let controllers = GCController.controllers()
for controller in controllers {
controller.motion?.valueChangedHandler = { (motion: GCMotion)->() in
if let delegate = self.motionDelegate {
delegate.motionUpdate(motion)
}
}
}
}
protocol ReactToMotionEvents {
func motionUpdate(motion: GCMotion) -> Void
}
我希望它实现的地方,在我看来是SKScene:
import SpriteKit
import GameController
class GameScene: SKScene,ReactToMotionEvents {
override func didMovetoView(view: SKView) {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.motionDelegate = self
}
func motionUpdate(motion: GCMotion) {
print("x: \(motion.useracceleration.x) y: \(motion.useracceleration.y)")
}
}