[問題] 關於加速度

看板MacDev作者 (聖誕青年)時間10年前 (2014/06/10 12:05), 編輯推噓1(103)
留言4則, 3人參與, 最新討論串1/1
我想要在螢幕中間放一個東西 當手機向下時, 那東西會往上移動 手機向上時, 東西會往下移動 看起來, 那東西就是不動的, 動的只有手機背景 當然事實上,動的是那東西 以下是我的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://www.ptt.cc/bbs/MacDev/M.1402373117.A.A17.html

06/10 14:17, , 1F
UIMotionEffect ? iOS 7 出的API
06/10 14:17, 1F

06/10 14:44, , 2F
我的網誌有 UIMotionEffect 的教學 : http://ppt.cc/Viit
06/10 14:44, 2F

06/10 16:04, , 3F
我有用cmmotion 目前感覺差不多
06/10 16:04, 3F

06/10 16:33, , 4F
他還是吃不了這東西:(
06/10 16:33, 4F
文章代碼(AID): #1JbeFzeN (MacDev)