7

新しい 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!")
}

super を呼び出してもしなくても、何も得られません。

4

3 に答える 3

2

リモートのモーションと向きの情報にアクセスする方法を介して:


まずNSNotificationCenter、コントローラーを見つけるために使用する必要があります。おそらく、アプリの起動時にこれを行うのが最善です。このようなもの:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil];  

接続後に次のコードを使用して、デバイス情報をプロパティに保存できます。

- (void)controllerDidConnect:(NSNotification *)notification {  
    self.myController = notification.object;  
}  

リモート プロファイルは、マイクロ ゲームパッド プロファイルのサブクラスです。モーションやその他のデータは、値変更イベント ハンドラーを追加することで追跡できます。

  GCMicroGamepad *profile =  self.myController.microGamepad  
  profile.valueChangedHandler= ^ (GCMicroGamepad *gamepad, GCControllerElement *element) {  
        if (self.myController.motion) {  
            NSLog(@"motion supported");  
            NSLog(@"gravity: %f %f %f", self.myController.motion.gravity.x, self.myController.motion.gravity.y, self.myController.motion.gravity.z);  
            NSLog(@"userAcc: %f %f %f", self.myController.motion.userAcceleration.x, self.myController.motion.userAcceleration.y, self.myController.motion.userAcceleration.z);  
            NSLog(@"rotationRate: %f %f %f", self.myController.motion.rotationRate.x, self.myController.motion.rotationRate.y, self.myController.motion.rotationRate.z);  
            NSLog(@"attitude: %f %f %f %f", self.myController.motion.attitude.x, self.myController.motion.attitude.y, self.myController.motion.attitude.z, self.myController.motion.attitude.w);  
        }  
    };  

于 2015-09-29T12:32:24.817 に答える