gpt4 book ai didi

ios - 如何配置我的应用程序以检测抖动运动事件?

转载 作者:行者123 更新时间:2023-12-01 17:59:34 27 4
gpt4 key购买 nike

所以让我首先澄清一下我已经实现了哪些代码

-(BOOL)canBecomeFirstResponder 
{
return YES;
}

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self becomeFirstResponder];
}

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

- (void)viewWillDisappear:(BOOL)animated
{
[self resignFirstResponder];
[super viewWillDisappear:animated];
}

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
NSLog(@"FUUU");
}
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
NSLog(@"FUUU");
}
}

这都在 UIViewController 类中

- (void) applicationDidFinishLaunching:(UIApplication*)application我已经设定
[application setApplicationSupportsShakeToEdit:YES];

然而它什么也没做,没有检测到任何单一的运动。我不确定还能做什么。这似乎对许多其他人有效,所以我很困惑为什么我与众不同......可能是因为它是通过 UINavigationController 吗?或者因为我通过 plist 加载主应用程序而我的主应用程序看起来像这样
retVal = UIApplicationMain(argc, argv, nil, nil);

我完全被难住了。

最佳答案

为了检测摇动手势,您需要继承 UIView 并实现以下方法(不要在 UIViewController 上实现这些方法):

  • (BOOL)canBecomeFirstResponder
  • (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

  • 然后将子类 View 添加到 UIViewController 并通过调用 -becomeFirstResponder 使其成为第一响应者。

    关于ios - 如何配置我的应用程序以检测抖动运动事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12315100/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com