【问题标题】:How can i move the image object smoothly when I am using accelerometer in iOS?在 iOS 中使用加速度计时如何平滑移动图像对象?
【发布时间】:2013-03-12 12:47:03
【问题描述】:

在我的应用程序中,我正在根据加速度计移动球,但球没有平稳移动。我需要在视图中平稳移动球。我该怎么做?

我通过在google上搜索使用了以下语句。但我没有得到平滑的对象

delta.x = 0.01 * delta.x + (1.0 - 0.01) * acceleration.x;
delta.y = 0.01 * delta.y + (1.0 - 0.01) * acceleration.y;

【问题讨论】:

  • 编写您的 CGAffineTransformMakeTranslation 动画以获得流畅的动画动作。您可以为此使用基本的 UIViewAnimation 块。

标签: iphone ios ipad object accelerometer


【解决方案1】:

试试:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
    point = CGPointMake(34*acceleration.x, -20*acceleration.y);
    image.center = CGPointMake(image.center.x+point.x,image.center.y);

}

【讨论】:

  • 我使用了这段代码,但我没有得到球 delta.x = 4*acceleration.x 的平滑运动; delta.y = -2*acceleration.y ;旋转 = 旋转 + (2.0f * ((float)rand() / (float)RAND_MAX) - 1.0f) * .01; //-1, 1 之间的随机数 scrollingBtn.transform = CGAffineTransformRotate(scrollingBtn.transform, rotate); scrollingBtn.center = CGPointMake(scrollingBtn.center.x + ballVelocity.x+delta.x,scrollingBtn.center.y + ballVelocity.y+(delta.y * -1));球在条形图像上弹跳我需要给平滑运动我怎么能?
【解决方案2】:

使用

[UIView beginAniations:@"AnimaionName" context:nil];

[UIView setAnimationDuration: 2.0f];

imageView.frame = CGRectMake(,,,);

[UIView 提交动画];

这将提供流畅的运动

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多