在 UITableViewController 中摇动 3.0

发布于 2024-08-21 12:13:45 字数 545 浏览 1 评论 0原文

在阅读了一些关于在 3.0 上实现抖动的帖子后,我想我明白了,但我没有接到任何电话:

motionBegan 动议结束 motionCancelled

这是我读过的一个例子: 如何检测 iPhone 的震动并进行编程

我确信我已经添加了

[self becomeFirstResponder];

-(BOOL)canBecomeFirstResponder {
NSLog(@"First responder");
return YES;
}

我应该为这些事件启用特殊代表吗?

我知道这些事件是由系统控制的,它们会传递给第一响应者,然后继续......

有什么想法吗?

谢谢

after reading some posts about implementing shaking on 3.0, I think I get the idea but I'm not getting any call to the:

motionBegan
motionEnded
motionCancelled

this is an example of what I've read:
how to detect and program around shakes for the iphone

I'm sure I've added the

[self becomeFirstResponder];

and the

-(BOOL)canBecomeFirstResponder {
NSLog(@"First responder");
return YES;
}

Should I enable a special delegate for those events ?

I understand that those events are controlled by the system, and they are passed to the first responder, and go on ...

any idea ?

thanks,

r.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧幽蓝 2024-08-28 12:13:45

我在让它发挥作用时遇到了很多问题,最后我放弃了并听从了 jandrea 的建议。他建议对 UIWindow 进行子类化并在那里实现 MotionEnded。这是他的帖子这里的引用,看看因为它还很远。

首先,我对 UIWindow 进行了子类化。这是
容易。创建一个新的类文件
具有 MotionWindow 等界面
: UIWindow (随意选择你的
自己的,当然)。添加一个像这样的方法:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"DeviceShaken" object:self];
    }
}

将@“DeviceShaken”更改为
您选择的通知名称。节省
文件。

现在,如果您使用 MainWindow.xib
(库存 Xcode 模板内容),进入
在那里改变你的班级
窗口对象从 UIWindow 到
MotionWindow 或任何你所说的
它。拯救xib。如果你设置了
UIWindow 以编程方式,使用您的
那里有新的 Window 类。

现在您的应用程序正在使用专门的
UIWindow 类。无论你想去哪里
被告知震动,注册
他们通知!像这样:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceShaken) name:@"DeviceShaken" object:nil];

要删除自己作为观察者的身份:

[[NSNotificationCenter defaultCenter] removeObserver:self];

I had loads of problems getting this to work and I finally gave up and followed jandrea's advice. He suggested subclassing UIWindow and implement the motionEnded there. This is a quote from his post here, look for it quite far down.

First, I subclassed UIWindow. This is
easy peasy. Create a new class file
with an interface such as MotionWindow
: UIWindow (feel free to pick your
own, natch). Add a method like so:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"DeviceShaken" object:self];
    }
}

Change @"DeviceShaken" to the
notification name of your choice. Save
the file.

Now, if you use a MainWindow.xib
(stock Xcode template stuff), go in
there and change the class of your
Window object from UIWindow to
MotionWindow or whatever you called
it. Save the xib. If you set up
UIWindow programmatically, use your
new Window class there instead.

Now your app is using the specialized
UIWindow class. Wherever you want to
be told about a shake, sign up for
them notifications! Like this:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceShaken) name:@"DeviceShaken" object:nil];

To remove yourself as an observer:

[[NSNotificationCenter defaultCenter] removeObserver:self];
孤独患者 2024-08-28 12:13:45

您在哪里调用becomeFirstResponder?您应该在 viewDidAppear 中执行此操作。这会被解雇吗?

Where do you call becomeFirstResponder? You should do it in viewDidAppear. Does this get fired?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文