cmmotionmanager

Swift 2 to Swift 3.0 motionManager

淺唱寂寞╮ 提交于 2019-12-04 05:21:30
问题 I am converting an app from swift 2 to swift 3 and I'm trying to use the CMMotionManager, but it gives me this error when I try to call the .startAccelerometerUpdates() function... No clue what's wrong though. This is how I initialize the manager: let motionManager = CMMotionManager() Trying to call the function: motionManager.startAccelerometerUpdates(to: OperationQueue.main) { [weak self] (data: CMAccelerometerData?, error: NSError?) in self!.outputAccelerationData(data!.acceleration) }

How do I adjust CMMotionManager data for orientation under iOS 8?

為{幸葍}努か 提交于 2019-12-02 07:20:51
问题 My application uses CMMotionManager to track device motion, but iOS always returns device motion data in the standard device orientation (home button at the bottom). To get the motion data into the same orientation as my UIView, I accumulate the view transforms from my view down to the window like this: CGAffineTransform transform = self.view.transform; for (UIView *superview = self.view.superview; superview; superview = superview.superview) { CGAffineTransform superviewTransform = superview

Safe update interval for startDeviceMotionUpdatesToQueue:withHandler:?

六月ゝ 毕业季﹏ 提交于 2019-12-02 01:09:55
问题 EDIT: added a global and now it's working. But I still have my doubts.. Please read on :) I want to get the acceleration exercised on the Y-axis whenever I need to and use it in different parts of my code. In this example I'm using it inside a while-loop for testing purposes.. My code is working but Am I using the the UpdateToQueue... method correctly or is this kind of an "unorthodox" way of achieving what I want? I've set the Update Interval at 30 ms, do you think this is a "safe" update

Obtain absolute rotation using CMDeviceMotion?

十年热恋 提交于 2019-11-30 17:51:28
问题 I'm building a simple game with Sprite Kit, the screen doesn't rotate but I want to know the angle the user is holding the phone for a game mechanic. The values I want to get can be easily retrieved with the accelerometer (x, y) but I have found this to be unreliable so I'm trying to archive better results with CMDeviceMotion . I could obtain the equivalent to data.acceleration.y but I can't figure out how to get the equivalent of data.acceleration.x . if let data = motionManager

CMDeviceMotion yaw values unstable when iPhone is vertical

点点圈 提交于 2019-11-30 08:46:49
In a iOS prototype I use a combination of CMDeviceMotion.deviceMotion.yaw and CLHeading.trueHeading to make stable compass heading that is responsive and accurate. This works well when the iPhone is held flat, where I have a graphical arrow that point to a stable compass heading. The problem appear when the iPhone is held vertical in portait mode. The UIDeviceOrientation constantly changes from UIDeviceOrientationFaceDown to UIDeviceOrientationFaceUp and back. This makes the yaw value to skip back and forth +/-180 degrees based on small changes of the pitch. Is it possible to lock the device

Measuring tilt angle with CMMotionManager

亡梦爱人 提交于 2019-11-30 06:12:36
问题 Suppose you are holding an iphone/ipad vertically in front of you with the screen facing you, in portrait orientation. You tilt the device to one side, keeping the screen facing you. How do you measure that static tilt angle using CMMotionManager? It seems a simple question which should have a simple answer, yet I cannot find any method that does not disappear into quaternions and rotation matrices. Can anyone point me to a worked example? 回答1: Look at gravity : self.deviceQueue = [

Motion Manager is not working in Swift

蓝咒 提交于 2019-11-29 13:24:29
I am try to use motion manager in Swift but the log inside my update block never prints. var motionManager: CMMotionManager = CMMotionManager() motionManager.accelerometerUpdateInterval = 0.01 println(motionManager.deviceMotionAvailable) // print true println(motionManager.deviceMotionActive) // print false motionManager.startDeviceMotionUpdatesToQueue(NSOperationQueue.currentQueue(), withHandler:{ deviceManager, error in println("Test") // no print }) println(motionManager.deviceMotionActive) // print false My Objective-C implementation works fine. Does anyone know why my update block isn't

Measuring tilt angle with CMMotionManager

最后都变了- 提交于 2019-11-28 15:28:56
Suppose you are holding an iphone/ipad vertically in front of you with the screen facing you, in portrait orientation. You tilt the device to one side, keeping the screen facing you. How do you measure that static tilt angle using CMMotionManager? It seems a simple question which should have a simple answer, yet I cannot find any method that does not disappear into quaternions and rotation matrices. Can anyone point me to a worked example? Look at gravity : self.deviceQueue = [[NSOperationQueue alloc] init]; self.motionManager = [[CMMotionManager alloc] init]; self.motionManager

Motion Manager is not working in Swift

冷暖自知 提交于 2019-11-28 07:19:14
问题 I am try to use motion manager in Swift but the log inside my update block never prints. var motionManager: CMMotionManager = CMMotionManager() motionManager.accelerometerUpdateInterval = 0.01 println(motionManager.deviceMotionAvailable) // print true println(motionManager.deviceMotionActive) // print false motionManager.startDeviceMotionUpdatesToQueue(NSOperationQueue.currentQueue(), withHandler:{ deviceManager, error in println("Test") // no print }) println(motionManager.deviceMotionActive

cameranode rotate as iOS device moving

廉价感情. 提交于 2019-11-27 20:14:28
It's 360 degree video player project. I add a cameranode( SCNNode ) to a rootnode, the cameranode was put at the center(0,0,0) of the SCNSphere , It can play video by now. Now I have to use devicemotion. I need to rotate the camera when device moves. Not just rotate a certain angle. (Not just device move, When I'm holding a device, my moving regard as the device moving. because I found if I use deviceMotion.attitude.roll , the cameranode only moves when device moves by itself, not when I circle around with device) When device is located in (x1,y1,z1) position, the cameranode would rotate as