我在视图中有一个 imageView。即使iphone静止了一段时间,它也会移动。为什么会这样?此外,图像对 iphone 的移动也没有快速响应。
这是我为此编写的代码:
我还为加速度计设置了 updateInterval 和委托。
#define kVelocityMultiplier 1000;
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
if(currentPoint.x < 0)
{
currentPoint.x=0;
ballXVelocity=0;
}
if(currentPoint.x > 480-sliderWidth)
{
currentPoint.x=480-sliderWidth;
ballXVelocity=0;
}
static NSDate *lastDrawTime;
if(currentPoint.x<=480-sliderWidth&¤tPoint.x>=0)
{
if(lastDrawTime!=nil)
{
NSTimeInterval secondsSinceLastDraw=-([lastDrawTime timeIntervalSinceNow]);
ballXVelocity = ballXVelocity + -acceleration.y*secondsSinceLastDraw;
CGFloat xAcceleration=secondsSinceLastDraw * ballXVelocity * kVelocityMultiplier;
currentPoint = CGPointMake(currentPoint.x + xAcceleration, 266);
}
slider.frame=CGRectMake(currentPoint.x, currentPoint.y, sliderWidth, 10);
}
[lastDrawTime release];
lastDrawTime=[[NSDate alloc]init];
}
谁能帮帮我?