检测模态视图何时显示

发布于 2024-07-26 23:08:17 字数 1017 浏览 7 评论 0原文

这是一个有趣的...我有一个应用程序,它有一个帮助屏幕并显示为模式视图。 主视图具有当设备摇动时发生的动作。 我不希望在显示帮助屏幕时发生该操作(播放声音)。

我尝试了一些事情...这是我的代码:

显示帮助屏幕:

- (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 技术交流群。

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

发布评论

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

评论(1

烏雲後面有陽光 2024-08-02 23:08:17

我假设加载模态控制器的视图控制器也是响应摇动动作的视图控制器。 如果是这种情况,那么您可以使用父视图控制器的 modalViewController 属性来查看模态控制器是否处于活动状态:

if(self.modalViewController != nil) {
    // Modal view controller is active; do nothing
    NSLog(@"Shake -- helpView is loaded");
    return;
} else {
    // No modal view controller; take action
    NSLog(@"Shake -- helpView is not loaded");
    [self performSomeAction];
}

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:

if(self.modalViewController != nil) {
    // Modal view controller is active; do nothing
    NSLog(@"Shake -- helpView is loaded");
    return;
} else {
    // No modal view controller; take action
    NSLog(@"Shake -- helpView is not loaded");
    [self performSomeAction];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文