
我试过打电话
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上面所说的,但是接着这个让它为我工作.这就是我做的.
在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)") } } 总结 以上是内存溢出为你收集整理的swift – 如何使用Apple TV遥控器获取动作事件全部内容,希望文章能够帮你解决swift – 如何使用Apple TV遥控器获取动作事件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)