【问题标题】:Shake Gesture isn't working in iPhone 4, Don't know why...?摇动手势在 iPhone 4 中不起作用,不知道为什么...?
【发布时间】:2010-11-12 06:53:11
【问题描述】:

我开发了一个 iPhone 应用程序,它使用摇动手势来旋转选择器视图的轮子。我使用 IOS 3.2 作为基础 sdk。我有一部用 IOS 4.0 更新的 iPhone 3GS,当我在这款 3GS 手机中执行我的应用程序时,它可以与 Shake Gesture 一起正常工作。但是当我在 iPhone 4 中运行它时,Shake Gesture 没有响应。我不明白它的原因,如果有人有 Solotion 请帮助我...下面我提供了一个我用来处理摇动手势的代码部分...。

#define kRowMultiplier          20
#define kAccelerationThreshold      2.2
#define kUpdateInterval         (1.0f/10.0f)



(void) accelerometer:(UIAccelerometer*)accelerometer didAccelerate: UIAcceleration*)acceleration{

    if (fabsf(acceleration.x) > kAccelerationThreshold || fabsf(acceleration.y) > kAccelerationThreshold || fabsf(acceleration.z) > kAccelerationThreshold) {       
        [progressView startAnimating];

        if (! isSpinning)
        {       
            if(!btnRegion.selected && !btnFlavor.selected && !btnPrice.selected)
            {
                // Need to have it stop blurring a fraction of a second before it stops spinning so that the final appearance is not blurred.
                [self stopBlurring];
                wheelingTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(shufflePickerView) userInfo:nil repeats:YES];
            }
            else 
            {
                [self shufflePickerView];
                [self performSelector:@selector(stopBlurring) withObject:nil afterDelay:2.7];
            }
        }
        isSpinning = YES;       
    }   

}

代码中的总和是错误的...我可以在 IOS 4.0 上通过模拟器测试它还是只需要使用 iPhone 4...?

【问题讨论】:

    标签: iphone


    【解决方案1】:

    感谢 Hugo 的解决方案,但我在很多天前找到了另一种方法,我想这很容易......

    我们可以这样做...

    -(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    
         if (event.type == UIEventSubtypeMotionShake) 
        {
                  //Put your code here what you want to do on a shake...
        }   
    }
    

    【讨论】:

      【解决方案2】:

      我也有同样的问题。 我在 iPhone 3G 上测试的代码工作正常,在 iPhone 4 上它不起作用。两者都在 iOS 4.2.1 上运行

      更新:使用了这种方法,效果很好: http://www.softvelopment.com/index.php/blogs/2010/03/19/3-adding-shake-recongnition-to-cocos2d-iphone-library-

      【讨论】:

      • 感谢 Hugo 的解决方案,但我在很多天前找到了另一种方法,我想这很容易......
      猜你喜欢
      • 1970-01-01
      • 2018-01-19
      • 2011-05-10
      • 2015-01-21
      • 2020-04-25
      • 2013-05-14
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多