Iphone 使用Core Motion和CATTransform3D旋转图像
我正在尝试设计一个应用程序,让它看起来好像你可以环顾一个物体。我已经走了相当远的路,但我不知道如何使物体像画框一样漂浮在空中(而不是平放在地上) 这是我的密码:Iphone 使用Core Motion和CATTransform3D旋转图像,iphone,objective-c,ios,Iphone,Objective C,Ios,我正在尝试设计一个应用程序,让它看起来好像你可以环顾一个物体。我已经走了相当远的路,但我不知道如何使物体像画框一样漂浮在空中(而不是平放在地上) 这是我的密码: CMMotionManager *motionManager = [[CMMotionManager alloc] init]; [motionManager setDeviceMotionUpdateInterval:0.1]; CMDeviceMotionHandler motionHandler = ^ (CMDeviceMo
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
[motionManager setDeviceMotionUpdateInterval:0.1];
CMDeviceMotionHandler motionHandler = ^ (CMDeviceMotion *motion, NSError *error)
{
[xLabel setText:[NSString stringWithFormat:@"X: %f, Yaw: %f", motion.userAcceleration.x, motion.attitude.yaw]];
[yLabel setText:[NSString stringWithFormat:@"Y: %f, Pitch: %f", motion.userAcceleration.y, motion.attitude.pitch]];
[zLabel setText:[NSString stringWithFormat:@"Z: %f, Roll: %f", motion.userAcceleration.z, motion.attitude.roll]];
CATransform3D transform;
transform = CATransform3DMakeRotation(motion.attitude.pitch, 1, 0, 0);
transform = CATransform3DRotate(transform, motion.attitude.roll, 0, 1, 0);
transform = CATransform3DRotate(transform, motion.attitude.yaw, 0, 0, 1);
myView.layer.sublayerTransform = transform;
//[myImage setNeedsDisplay];
};
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue currentQueue] withHandler:motionHandler];
这会使图片看起来像是平放在桌子上,但它应该看起来像是挂在墙上的。有什么办法吗?如果它看起来是平的,你只需要在俯仰旋转代码中添加正确的旋转,使它在默认情况下直立。尝试将俯仰旋转更改为下面的代码
transform=CATTransformerM3dMakeRotation(运动、姿态、俯仰+M_PI_2,1,0,0)代码>
如果颠倒了,试着做减法