在UITableViewController中摇动3.0 [英] shaking on 3.0 in a UITableViewController

查看:132
本文介绍了在UITableViewController中摇动3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了一些有关在3.0上实现摇动的文章之后,我想我明白了,但是我没有接到任何电话:

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 运动结束 motionCancelled

motionBegan motionEnded motionCancelled

这是我所读内容的一个示例: 如何针对iPhone的震动进行检测和编程

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

我确定我已经添加了

[self becomeFirstResponder];

-(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 ...

有什么主意吗?

谢谢

r.

推荐答案

我遇到了很多使它无法正常工作的问题,最后我放弃了,并听从了詹德里亚的建议.他建议将UIWindow子类化,并在那里实现motionEnded.这是他的帖子此处的引言因为它已经很低了.

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.

首先,我将UIWindow子类化.这是 十分简单.创建一个新的类文件 与诸如MotionWindow之类的接口 :UIWindow(随意选择您的 自己的,natch).添加这样的方法:

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];
    }
}

将@"DeviceShaken"更改为 您选择的通知名称.救 文件.

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

现在,如果您使用MainWindow.xib (库存的Xcode模板素材),进入 在那里,改变你的班级 从UIWindow到Window对象 MotionWindow或您所说的任何东西 它.保存XIB.如果您设置 以编程方式使用UIWindow,请使用 那里有新的Window类.

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.

现在您的应用正在使用专用 UIWindow类.无论您想去哪里 被告知要摇一摇,报名参加 他们的通知!像这样:

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];

这篇关于在UITableViewController中摇动3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆