小编Jos*_*mez的帖子

iOS DeviceMotion 横向与纵向上的偏航和滚动

我正在使用陀螺仪在 iOS 上实现 360 度视频查看器,我需要为视频进行两次旋转,我使用了这个;

self.motionManager.deviceMotionUpdateInterval = 1.0/60.0;
    if (self.motionManager.isDeviceMotionAvailable) {
        CMDeviceMotion *deviceMotion = self.motionManager.deviceMotion;
        CMAttitude *currentAttitude = deviceMotion.attitude;
        //[self.motionManager startDeviceMotionUpdates];
        [self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryZVertical];
    }
Run Code Online (Sandbox Code Playgroud)

然后我这样做:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
CMDeviceMotion *currentDeviceMotion = self.motionManager.deviceMotion;
CMAttitude *currentAttitude = currentDeviceMotion.attitude;     
float roll  = currentAttitude.roll;
float pitch = currentAttitude.pitch;
float yaw = currentAttitude.yaw;

if (isLandscape)
{
    _player.rotation = -yaw + currentLocation.x;

    // 0 roll is phone flat, so we need to rotate -90 degrees to adjust vertical phone
    if (orientation == UIDeviceOrientationLandscapeLeft) …
Run Code Online (Sandbox Code Playgroud)

portrait objective-c ios devicemotion 360-virtual-reality

5
推荐指数
0
解决办法
857
查看次数