motionEnded 工作正常,直到我单击 webView 中的链接
我使用这段代码来进行震动检测,并且在大多数情况下它工作得很好:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {
if ( event.subtype == UIEventSubtypeMotionShake )
{
NSLog (@"Shake Called");
}
}
我相信要使其工作,我还需要使用这些,我有:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewDidDisappear:animated];
}
这一切都很好,并且 motionEnded ,直到我单击程序上的
webView
中的链接。我可以在视图中上下滚动,并且摇动仍然有效,但是一旦视图加载新页面,当我摇动时,motionEnded
就会停止被调用。这种情况在模拟器和真实设备(iPhone 3G、iOS4)上都会发生。根据我有限的理解,我相信这与急救人员有关,但我可能是错的!
I'm using this code to do shake detection, and for the most part it works fine:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {
if ( event.subtype == UIEventSubtypeMotionShake )
{
NSLog (@"Shake Called");
}
}
I believe for this to work, I also needed to use these, which I have:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewDidDisappear:animated];
}
This all works great, and motionEnded
is called every time I shake, until I click through a link in a webView
on my program. I can scroll up and down in the view and shake still works, but as soon as the view loads a new page, motionEnded
stops being called when I shake. This occurs both in the simulator and on a real device (iPhone 3G, iOS4). From my limited understanding, I believe it has something to do with first responders, but I could be wrong there!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经设法回答了我自己的问题。对于可能有类似问题的其他人的参考,问题是一旦您单击 webView 中的链接(或编辑文本框或某些类似操作),viewController 将不再是第一响应者。为了解决我的问题,答案是在新页面加载后使 viewController 再次成为第一响应者:
I have managed to answer my own question. For the reference of others who may have similar problems, the issue is that the viewController stops being the first responder once you click a link in a webView (or edit a text box, or some similar action). To fix the issue in my case, the answer was to make the viewController the first responder again after the new page loads:
我有同样的问题,但是当网络视图完成加载时成为第一响应者并不能解决我的问题。我知道当加载新页面时 webViewDidFinishLoad 会被调用,我也知道当我通过点击 Web 视图然后摇动或模拟摇动来聚焦 Web 视图时,motionEnded 会被调用。
I have the same problem, but becoming first reponder when web view finishes loading doesn't solve it for me. I know webViewDidFinishLoad gets called when a new page has been loaded, and I also know motionEnded gets called when I focus the web view by tapping it and then shaking or simulating shake.