检测模态视图何时显示
这是一个有趣的...我有一个应用程序,它有一个帮助屏幕并显示为模式视图。 主视图具有当设备摇动时发生的动作。 我不希望在显示帮助屏幕时发生该操作(播放声音)。
我尝试了一些事情...这是我的代码:
显示帮助屏幕:
- (IBAction)helpButtonPressed:(id) sender {
helpViewController = [[HelpViewController alloc] init];
[self presentModalViewController:helpViewController animated:YES];
}
释放帮助屏幕:
- (IBAction)buttonPressed:(id) sender {
[self dismissModalViewControllerAnimated:YES];
}
我尝试了以下操作但没有成功:
if ([helpViewController.view isHidden ]) {
NSLog(@"Shake -- helpView is loaded");
} else {
NSLog(@"Shake -- helpView is not loaded");
}
if ([helpViewController isViewLoaded]) {
NSLog(@"Shake -- helpView is loaded");
} else {
NSLog(@"Shake -- helpView is not loaded");
}
if ([self isViewLoaded]) {
NSLog(@"Shake -- helpView is loaded");
} else {
NSLog(@"Shake -- helpView is not loaded");
}
我在想的是是否有一个函数可以让我检测是否正在显示帮助视图,当设备摇动时,我将返回而不播放声音......
有什么想法吗?
This is a fun one... I have an application that has a help screen and is displayed as a modal view. The main view has an action that occurs when the device is shaken. I do not want the action to occur (sounds are played) when the help screen has been displayed.
I have tried a few things... here is my code:
To display the help screen:
- (IBAction)helpButtonPressed:(id) sender {
helpViewController = [[HelpViewController alloc] init];
[self presentModalViewController:helpViewController animated:YES];
}
To release the help screen:
- (IBAction)buttonPressed:(id) sender {
[self dismissModalViewControllerAnimated:YES];
}
I tried the following with no success:
if ([helpViewController.view isHidden ]) {
NSLog(@"Shake -- helpView is loaded");
} else {
NSLog(@"Shake -- helpView is not loaded");
}
if ([helpViewController isViewLoaded]) {
NSLog(@"Shake -- helpView is loaded");
} else {
NSLog(@"Shake -- helpView is not loaded");
}
if ([self isViewLoaded]) {
NSLog(@"Shake -- helpView is loaded");
} else {
NSLog(@"Shake -- helpView is not loaded");
}
What I was thinking is if there is a function to allow me to detect if the help view is showing, I will return without playing the sounds when the device is shaken....
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设加载模态控制器的视图控制器也是响应摇动动作的视图控制器。 如果是这种情况,那么您可以使用父视图控制器的 modalViewController 属性来查看模态控制器是否处于活动状态:
I'm assuming that the view controller which loads the modal controller is also the view controller that responds to the shake action. If that's the case, then you can use the parent view controller's
modalViewController
property to see whether the modal controller is active: