简体   繁体   English

关闭iOS原生MPVolumeView音频路由菜单

[英]Dismiss iOS native MPVolumeView audio route menu

I'm using MPVolumeView to allow the user to control his preferred audio route when using my application. 我使用MPVolumeView允许用户在使用我的应用程序时控制他喜欢的音频路径。

The view is presented by this code: 该代码显示了该视图:

self.volumeView = [[MPVolumeView alloc] initWithFrame:self.view.frame];
self.volumeView.showsVolumeSlider = NO;
[self.view addSubview:self.volumeView];

When the user taps the audio route button a menu appears with the available options. 当用户点击音频路由按钮时,会出现一个带有可用选项的菜单。

The issue: The screen that shows the volume view, might need to be hidden because of various events my application handles and I would like to hide the audio route menu at the same time (if it's currently presented) 问题:显示音量视图的屏幕可能需要隐藏,因为我的应用程序处理各种事件,我想同时隐藏音频路由菜单(如果它当前显示)

My question: Does anybody know if it's possible to manually dismiss MPVolumeView's audio route selection menu without the user having to press the cancel button? 我的问题:有没有人知道是否可以手动关闭MPVolumeView的音频路由选择菜单而无需用户按下取消按钮?

Thanks! 谢谢!

on iOS 8, you can use below code which use private API 在iOS 8上,您可以使用以下使用私有API的代码

            NSArray *windows = [[UIApplication sharedApplication] windows];
    for (UIWindow *window in windows) {
        if ([NSStringFromClass([window class]) isEqualToString:@"_MPAVRoutingSheetSecureWindow"]) {
            UIView *view = [window.subviews firstObject];
            if ([NSStringFromClass([view class]) isEqualToString:@"MPAVRoutingSheet"]) {
                [view performSelector:@selector(dismiss)];
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM