iOS 4 core motion attitude in landscape orientation

佐手、 提交于 2020-01-02 06:49:06

问题


I've been trying to rotate my view based on the CMAttitude returned from CMMotionManager specifically the pitch=x and roll=y. I'm using a reference attitude to set my horizon. This works great for portrait mode but the minute i try to do it for a landscape view it goes wrong. As the phone is now rotated 90 ccw I was hoping that coremotion would know landscape was in place and keep the pitch and roll useful. Instead I still have the axis pointing their original way. To try and compensate I simply changed the sign on roll=x and switched pitch=y. This appeared to work till I held the device in front of me and the turned around 180 degrees. The view spun upside down and inverted.

My spidy sense is telling me I need to apply a proper transformation on the pitch roll and yaw to reorientate the attitude

I'm hoping some geniuses or genii can help me. Maths is obviously not a strong point of mine.


回答1:


Your are right, changing pitch and roll will lead into serious trouble. The simplest way seems to work with a new reference attitude like in CoreMotionTeapot sample. Just when the orientation change is detected, you have to grab the current attitude before multiplying it with your former reference attitude and set it as new reference attitude.



来源:https://stackoverflow.com/questions/5063697/ios-4-core-motion-attitude-in-landscape-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!