我正在尝试设计一个应用程序,使其看起来好像可以查看物体的各个方面。我已经做了很多工作,但是我无法弄清楚如何使物体浮在空中,就像一张照片框架一样(而不是平放在地上)。
这是我的代码:
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];
这将使图片看起来像是平放在桌子上,但实际上应该看起来像是挂在墙上。有什么好的想法吗?