本文介绍了在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

motionBeganmotionEndedmotionCancelled

这是我所读内容的一个示例:如何针对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.

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

现在,如果您使用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];
[[NSNotificationCenter defaultCenter] removeObserver:self];

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

09-02 21:56