作者santaclub (圣诞青年)
看板MacDev
标题[问题] 关於加速度
时间Tue Jun 10 12:05:13 2014
我想要在萤幕中间放一个东西
当手机向下时, 那东西会往上移动
手机向上时, 东西会往下移动
看起来, 那东西就是不动的, 动的只有手机背景
当然事实上,动的是那东西
以下是我的code
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
我将手机横放, 因此选取x来做标准
float adjustThing = acceleration.x;
sumY = sumY + (acceleration.y-lastY);
sumZ = sumZ + (acceleration.z-lastZ);
//这边是要校正标准线,当手机被斜拿时, 重力将不再是9.8
if(fabsf(sumY) > 0.02 || fabsf(sumZ) >0.02)
{
sumZ = 0;
sumY = 0;
standard = acceleration.x;
}
速度 = 加速度之和
speed = speed + adjustThing-standard;
位移 = 速度之和
distance = distance +speed;
movingLALA.position =
CGPointMake(movingLALA.position.x, oriPosition.y - distance);
我将物品的原始位置 再加上偏移量
lastX = adjustThing;
lastY = acceleration.y;
lastZ = acceleration.z;
记录上一轮的资讯,以更正偏差值
}
我log出来x的值之後, 并不如我想像的变化, 这个物品会在萤幕中飘来飘去...
请问有什麽其他的方法可以实作这样的东西吗? (准确地找出装置移动的位移量,非旋转)
感恩
--
˙ . . . . ‧
.◢◣. . .
◢█◣. ☆ █ ███ █◣█ ███ ███ ███ ██ █▉█ ██◣ ˙
▇
█▆▇
█ ▇ █▇ γ███▇
██▆
█▇█ ██▆▅
█▇
█▉█ █▇█▆▅▆▇
. ▇ █ █ξ ◥█ █ ι ☆ █ ﹎﹎﹎ ﹎﹎﹎ ███ █▇█ .
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.165.151.188
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MacDev/M.1402373117.A.A17.html
1F:→ shinrenpan:UIMotionEffect ? iOS 7 出的API 06/10 14:17
3F:→ santaclub:我有用cmmotion 目前感觉差不多 06/10 16:04
4F:→ santaclub:他还是吃不了这东西:( 06/10 16:33