我正在尝试在Xcode 4.3.3中创建一个应用程序,其中当使用加速度计的z轴为正时显示一个图像。但是,当z轴变为负值时,我希望显示不同的图像。我是初学者,所以如果你能告诉我我应该编写代码的文件会很棒。
谢谢!
答案 0 :(得分:1)
查看以下链接以了解UIAccelerometer
http://homepages.ius.edu/rwisman/C490/html/chapter22.htm
http://www.edumobile.org/iphone/iphone-programming-tutorials/how-to-use-accelerometer-in-iphone/
http://www.ifans.com/forums/threads/tutorial-simple-accelerometer-source-code.151394/
您需要在以下功能中进行更改
- (void)accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration
{
if(acceleration.z<0) {
imageview.image = //Display image to be displayed when z is negative
}
else {
imageview.image = //Display image to be displayed when z is positive
}
}