Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何检测 iPhone 正在向特定方向(X 轴)移动?你能展示一些示例代码吗?
您可以在 UIAccelerometer 的帮助下执行此操作,并通过以下方式检查手机在 x 轴上的移动:
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)aceler { if (sqrt(aceler.x * aceler.x) > 1.5f) { //write your code here } }
希望这可以帮助。
谢谢,
马杜普