简体   繁体   English

使用CABasicAnimations和CoreMotion移动UIView

[英]Moving UIView with CABasicAnimations and CoreMotion

I want to move my UIView up and down (x axis) with the accelerometer but keep it within the screen. 我想使用加速度计上下移动UIView(x轴),但将其保持在屏幕内。 Currently, I can't get it to move in coordination with the accelerometer. 目前,我无法使其与加速度计配合使用。 I have an NSTimer that fires every 0.05 seconds (which is how often the Accelerometer updates) and calls a method which attempts to move the UIView. 我有一个NSTimer,它每0.05秒触发一次(这是Accelerometer更新的频率),并调用一个尝试移动UIView的方法。 How can I get the UIView to move based on the accelerometer's movement? 如何使UIView基于加速度计的运动而运动?

.05 seconds is too short an interval to do any meaningful animation. .05秒的间隔太短,无法制作任何有意义的动画。 Think in terms of .1 seconds or so at a minimum. 至少以0.1秒左右的时间思考。

If you can't get animations to work, post your code. 如果无法播放动画,请发布代码。 Also tell us if you are using Storyboards (the default) or XIB files. 还告诉我们您使用的是Storyboard(默认)还是XIB文件。

You really need to have a look at : 您确实需要看看:

  1. http://tech.pro/tutorial/968/iphone-tutorial-reading-the-accelerometer http://tech.pro/tutorial/968/iphone-tutorial-reading-the-accelerometer
  2. iTuneU - Standford - Developing iOS 7 Apps for iPhone and iPad - video 17. Camera, Core Motion, Application Lifecycle iTuneU-Standford-开发适用于iPhone和iPad的iOS 7应用 -视频17.相机,Core Motion,应用程序生命周期

If you have time, Standford course on iPhone/iPad Dev are TOP ! 如果您有时间,iPhone / iPad Dev上的斯坦福德课程当然是一流的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM