简体   繁体   English

带有XCode 4的MPVolumeView(故事板)

[英]MPVolumeView with XCode 4 (Storyboards)

How do you make a slider that adjusts the volume level of the device with storyboarding? 如何制作带有情节提要的滑块来调节设备的音量水平? I haven't found any information on this relevant to XCode 4. Is MPVolumeView still the way to go? 我还没有找到与XCode 4相关的任何信息。MPVolumeView仍然是要走的路吗? If so, how do I implement it? 如果是这样,我该如何实施?

Thanks. 谢谢。

You can still use an MPVolumeView in Xcode 4.x and iOS5. 您仍然可以在Xcode 4.x和iOS5中使用MPVolumeView。 Simply import the MediaPlayer framework (link to it in your project settings, too) and use something like this: 只需导入MediaPlayer框架(在您的项目设置中也链接到它),然后使用类似以下的内容:

MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(0,0,120,15)];
[someView addSubview:volumeView];

This will give you the slider that will change system volume when dragged. 这将为您提供可以在拖动时更改系统音量的滑块。

If you want to use a slider, you can add one to your view and link it to an action in the corresponding view controller. 如果要使用滑块,则可以在视图中添加一个并将其链接到相应视图控制器中的动作。 The action looks like this: 该动作如下所示:

- (IBAction)volumeSliderChanged:(id)sender
{
    UISlider *slider = (UISlider *)sender;
    float newVolume = slider.value;
    // Set new volume
}

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

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