“返回”时的自定义行为按下导航栏中的按钮

发布于 2024-10-16 16:11:27 字数 348 浏览 5 评论 0原文

我知道您可以向 UINavigationBar 添加自定义“后退”按钮,但这样做会删除左侧锥形的现有按钮,如 在导航栏中按下后退按钮时会发生什么

有什么方法可以保留后退按钮的现有行为和外观,但也可以按下时通知?

基本上,我希望我的应用程序在触摸任何按钮时播放声音。我可以通过 UITabBarController 的委托来完成此操作,但 UINavgationBarController 的委托没有这样的功能。

I know that you can add a custom "back" button to a UINavigationBar, but doing so removes the existing button with the tapered left side, as described in What happens when back button is pressed in navigationBar

Is there any way to keep the existing behavior and look of the back button, but also be informed when it is pressed?

Basically, I want my app to play a sound whenever any button is touched. I can do it with UITabBarController via its delegate, but the delegate for UINavgationBarController has no such functionality.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

痴骨ら 2024-10-23 16:11:27

以下是视图控制器消失的可能性。

  1. 单击按钮(backBarButtonItem 除外)。
  2. 单击 backBarButtonItem

无论哪种情况都会调用 viewWillDisappear: 方法。保留一个布尔标志。我们将其命名为 isAnyButtonClicked。并在单击任何按钮时设置 isAnyButtonClicked = YES。并重写viewWillDisappear:方法,并在没有单击按钮时播放声音(即isAnyButtonClicked == NO)。可能你的 viewWillDisappear: 看起来像,

- (void)viewWillDisappear:(BOOL)animated {

    [super viewWillDisappear:animated];

    if (!isAnyButtonClicked) {

        // Play sound
        isAnyButtonClicked = NO;
    }
}

The following are the possibilities for a View Controller to disappear.

  1. Clicking on a button (other than backBarButtonItem).
  2. Clicking on the backBarButtonItem

Either case viewWillDisappear: method will be called. Keep a boolean flag. Lets name it isAnyButtonClicked. And set isAnyButtonClicked = YES whenever any button is clicked. And override the viewWillDisappear: method, and play the sound if no button is clicked(ie., isAnyButtonClicked == NO). Probably your viewWillDisappear: would look like,

- (void)viewWillDisappear:(BOOL)animated {

    [super viewWillDisappear:animated];

    if (!isAnyButtonClicked) {

        // Play sound
        isAnyButtonClicked = NO;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文