3
我正在开发一个应用程序,当用户打开时,将会有一个由CMMotionManager控制的图像,该图像根据用户倾斜设备的方向进行移动。CMMotionManager参考框架
... ...
这是我的代码启动装置运动。
motionManager = [[CMMotionManager alloc] init];
motionManager.showsDeviceMovementDisplay = YES;
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical];
这是我用来控制我的图像参考设备的运动的代码。
- (void)drawRect:(CGRect)rect
{
if (placesOfInterestCoordinates == nil) {
return;
}
mat4f_t projectionCameraTransform;
multiplyMatrixAndMatrix(projectionCameraTransform, projectionTransform, cameraTransform);
int i = 0;
for (MovingImage *poi in [placesOfInterest objectEnumerator]) {
vec4f_t v;
multiplyMatrixAndVector(v, projectionCameraTransform, placesOfInterestCoordinates[i]);
float x = (v[0]/v[3] + 1.0f) * 0.5f;
float y = (v[1]/v[3] + 1.0f) * 0.5f;
if (v[2] < 0.0f) {
CGPoint movingTo = CGPointMake(x*self.bounds.size.width, self.bounds.size.height-y*self.bounds.size.height);
if (movingTo.x < -118) {
movingTo.x = -118;
}
if (movingTo.x > 542) {
movingTo.x = 542;
}
if (movingTo.y < 215) {
movingTo.y = 215;
}
if (movingTo.y > 390) {
movingTo.y = 390;
}
poi.view.center = movingTo;
poi.view.hidden = NO;
} else {
poi.view.hidden = YES;
}
i++;
}
}
的图像是在屏幕的中间很少当用户打开应用程序时,图像通常是向右或向左旋转90度的起始位置,或者正好在中间一致。
我认为CMAttitudeReferenceFrameXArbitraryCorrectedZVertical
是问题,但我也试过CMAttitudeReferenceFrameXArbitraryZVertical
这也不起作用。 如果有用,我的项目是here,对于任何有兴趣的人。我也使用Apple pARk示例代码。