本文介绍了使用MPVolumeView后如何重新打开系统卷覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为非原生声音格式构建音频播放器。应用程序的层次结构基于iPod.app。它有一些 UITableView 和一个 UIView TrackView )使用 MPVolumeView 允许用户更改屏幕上的音量。直到第一次 TrackView 变为可见时,使用硬件按钮更改音量会按预期(和所需)显示系统音量叠加。当 TrackView 可见时,由于 MPVolumeView 在使用硬件按钮更改音量时更新,因此这些叠加不会出现(同样希望)。

I'm building an audio player for a non-native sound format. The application's hierarchy is based on the iPod.app. It has a number of UITableView's and one UIView (TrackView) that uses an MPVolumeView to allow the user to change the volume onscreen. Until the first time TrackView becomes visible changing the volume using the hardware buttons displays the system volume overlay as expected (and desired). When TrackView is visible these overlays don't appear since the MPVolumeView updates when changing the volume with the hardware buttons (also desired).

问题在于:一旦退出 TrackView ,使用时系统音量叠加不会出现硬件音量按钮。我已尝试以编程方式在 TrackViewController viewWillAppear:中分配,创建和添加 MPVolumeView ,然后删除,释放和修改同样的 MPVolumeView TrackViewController viewWillDisappear:

Here's the problem: once you back out of TrackView the system volume overlay does not appear when using the hardware volume buttons. I have tried programmatically allocing, creating and adding the MPVolumeView in TrackViewController viewWillAppear: and then removing, releasing and nil-ing the same MPVolumeView in TrackViewController viewWillDisappear:.

这个不会发生在iPod.app中。退出包含 MPVolumeView 的视图后,使用硬件音量按钮时会显示系统音量叠加。

This does not happen in the iPod.app. Once backing out of the view that contains an MPVolumeView the system volume overlays display when using the hardware volume buttons.

我缺少什么?

更新2:这似乎是MPVolumeView中的一个错误在iOS 3.2之后的某个时间推出并在4.2中修复。

Update 2: This appears to be a bug in MPVolumeView that was introduced sometime after iOS 3.2 and fixed in 4.2.

更新:我做了一个简单的从具有相同行为的默认基于窗口的应用程序项目中减少。一旦MPVolumeView变得可见,系统卷覆盖层就再也不会在应用程序中看到。

Update: I made a simple reduction from the default window-based application project that exhibits the same behavior. Once an MPVolumeView becomes visible the system volume overlays are never seen in the application again.

VolumeAppDelegate.h:

VolumeAppDelegate.h:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface VolumeAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    IBOutlet UIView *volumeView;
    IBOutlet MPVolumeView *mpVolumeView;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

-(IBAction)toggleVolumeView:(id)sender;

@end

VolumeAppDelegate.m:

VolumeAppDelegate.m:

#import "VolumeAppDelegate.h"

@implementation VolumeAppDelegate

@synthesize window;

-(IBAction)toggleVolumeView:(id)sender{

    if (mpVolumeView == nil){
        mpVolumeView = [[MPVolumeView alloc] initWithFrame:volumeView.bounds];
        [volumeView addSubview:mpVolumeView];
    }
    else{
        [mpVolumeView removeFromSuperview];
        [mpVolumeView release];
        mpVolumeView = nil;
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    [self.window makeKeyAndVisible];
    mpVolumeView = nil;
    return YES;
}

- (void)dealloc {
    [window release];
    [super dealloc];
}

@end

您需要添加将MediaPlayer框架添加到Xcode中的项目中,并在Interface builder中打开MainWindow.xib,添加UIView和UIButton IBOutlets,并将IBAction连接到UIButton。

You'll need to add the MediaPlayer framework to your project in Xcode and open up MainWindow.xib in Interface builder to add the UIView and UIButton IBOutlets and hookup the IBAction to the UIButton.

推荐答案

令人遗憾的是早期版本的iOS中的私有框架存在问题。

This is sadly an issue with the private framework in the earlier versions of iOS.

我理解你希望为此做出解决方案,但是它会导致你的代码操纵私有框架,使你的应用程序无法通过审批。

I understand your wish to make a solution for this, but it would cause your code to manipulate the private framework, making your app unable to pass approval.

幸运的是,有这个错误的版本范围很短,而且随着这些版本流通的设备越来越薄。

Fortunately, the version span that had this error is short, and the number of devices in circulation with these version are growing thinner by the minute.

这篇关于使用MPVolumeView后如何重新打开系统卷覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 14:21