【问题标题】:Shake Detection iPhone 3.0 not working震动检测 iPhone 3.0 不工作
【发布时间】:2009-10-10 12:23:37
【问题描述】:

我有一个 ViewController 可以完美地与触发动作的按钮配合使用。我想用一个震动事件替换按钮,所以我用谷歌搜索它并创建了一个继承自 UIView 的 ShakeDetector 类

我的实现如下:

@implementation ShakeDetector

    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
    }

    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        if (motion == UIEventSubtypeMotionShake )
        {
            // User was shaking the device. Post a notification named "shake".
            //[[NSNotificationCenter defaultCenter] postNotificationName:@"spin" object:self];
            NSLog(@"sss");
        }
    }

    - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {   
    }

@end

但我不能让它工作......有什么帮助吗?

谢谢

【问题讨论】:

    标签: iphone events triggers detection shake


    【解决方案1】:

    放:

        -(BOOL)canBecomeFirstResponder
    {
        return YES;
    }
    

    为了你的看法:

      - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [self becomeFirstResponder];
    }
    - (void)viewDidDisappear:(BOOL)animated {
        [self resignFirstResponder];
        [super viewDidDisappear:animated];
    }
    

    也可以写在viewWillAppear和viewWillDisappear中

    【讨论】:

      猜你喜欢
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 2011-07-17
      • 1970-01-01
      相关资源
      最近更新 更多