iOS Calc device orientation use accelerometer

blog :http://blog.sallarp.com/iphone-accelerometer-device-orientation/

 

float x = -accelerometerData.acceleration.x;

            float y = accelerometerData.acceleration.y;

            float angle = atan2(y, x);

            

            if(angle >= -2.25f && angle <= -0.75f) {

                currentOrientation = UIInterfaceOrientationPortrait;

            } else if(angle >= -0.75f && angle <= 0.75){

                currentOrientation = UIInterfaceOrientationLandscapeRight;

            } else if(angle >= 0.75f && angle <= 2.25f) {

                currentOrientation = UIInterfaceOrientationPortraitUpsideDown;

            } else if(angle <= -2.25f || angle >= 2.25f) {

                currentOrientation = UIInterfaceOrientationLandscapeLeft;

            }

posted on 2013-11-22 14:02  jhondge  阅读(250)  评论(0编辑  收藏  举报

导航