简体   繁体   English

如何在iOS上制作滑块音量控制器? Objective-C,iOS 7(或8),xcode 5(或6)

[英]How to make a slider volume controller on iOS? Objective-C, iOS 7 (or 8), xcode 5 (or 6)

I am learning to develop iphone apps and I have a simple question. 我正在学习开发iPhone应用程序,但有一个简单的问题。

I am making a really simple app which allows the user to set the volume of the device on the settings screen using a slider instead of the volume buttons. 我正在制作一个非常简单的应用程序,它允许用户使用滑块而不是音量按钮在设置屏幕上设置设备的音量。

It may be quite obvious for experienced developers but I just can't find the answer I am looking for. 对于经验丰富的开发人员来说,这可能是显而易见的,但是我找不到所需的答案。

My question is: 我的问题是:

How can I make this slider? 如何制作此滑块?

Basically I want to do this (image: https://www.dropbox.com/s/b81bzdwyrab0ha7/slider.png?dl=0 ): 基本上我想这样做(图片: https : //www.dropbox.com/s/b81bzdwyrab0ha7/slider.png?dl=0 ):

I used to think that I could use a regular UISlider but some documentation says that I need to use something called a MPVolumeView. 我曾经认为我可以使用常规的UISlider,但是一些文档说我需要使用一种称为MPVolumeView的东西。 The problem is that I can´t find a good tutorial that tells how to use this explicity. 问题是我找不到一个很好的教程来告诉您如何使用此显式方法。

I found this link on the apple documentation but I dont understand how this works. 我在苹果文档中找到了此链接,但我不了解其工作原理。 http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPVolumeView_Class/Reference/Reference.html And the description says: Use a volume view to present the user with a slider control for setting the system audio output volume, and a button for choosing the audio output route. http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPVolumeView_Class/Reference/Reference.html并且说明说: 使用音量视图向用户展示用于设置系统音频的滑块控件输出音量,以及用于选择音频输出路径的按钮。 When first displayed, the slider's position reflects the current system audio output volume. 首次显示时,滑块的位置反映了当前系统音频输出音量。 As the user drags the slider, the changes update the volume. 当用户拖动滑块时,更改将更新音量。 If the user presses the device volume buttons while sound is playing, the slider moves to reflect the new volume. 如果用户在播放声音时按下设备的音量按钮,则滑块将移动以反映新的音量。

This is exactly what I want but I dont understand the example it gives. 这正是我想要的,但我不理解它给出的示例。 If you could please tell me how t make this slider work, even if it is on a new one-view project, I would really appreciate it. 如果您能告诉我如何使此滑块起作用,即使它在一个新的单视图项目中,我也将不胜感激。

Also I am aware that this method also creates an airPlay button next to the volume slider. 我也知道这种方法还在音量滑块旁边创建了一个airPlay按钮。 Is there a way to delete this button? 有没有办法删除此按钮? (My app is a simple productivity app so I only want the slider, not the airplay button). (我的应用程序是一个简单的生产力应用程序,因此我只需要滑块,而不需要播放按钮)。

I also understand that this will not work on the simulator. 我也知道这在模拟器上不起作用。 How am I supposed to know that this will work without having to test it on an actual device (I am not registered as a developer yet)? 我如何知道无需在实际设备上进行测试就可以正常工作(我尚未注册为开发人员)?

Plus, I only know objective-c, not swift . 另外, 我只知道Objective-C,而不是Swift If you could please restrain from using swift in your answers I would apreaciate. 如果可以的话,请不要在回答中使用敏捷,我对此表示赞赏。

Thank you so much for your help. 非常感谢你的帮助。

PD: English is not my first language. PD:英语不是我的母语。 Sorry for any mistakes I made. 对不起,我犯了任何错误。

The MPVolumeView class is designed to let you do exactly this. MPVolumeView类旨在让您完全做到这一点。 It's in MediaPlayer.framework, so add that to your app to make things build correctly. 它位于MediaPlayer.framework中,因此请将其添加到您的应用中以使构建正确。

You create it and make it visible the way you instantiate any other subclass of UIView, which you probably know by now. 您创建它并以实例化UIView的任何其他子类的方式使其可见,您现在可能已经知道了。

You disable the routing button by setting the "showsRoutingButton" property to false. 您可以通过将“ showsRoutingButton”属性设置为false来禁用路由按钮。

"How am I supposed to know that this will work without having to test it on an actual device?" “我应该如何知道这种方法无需在实际设备上进行测试就能起作用?”

By seeing that it's been there since iOS 2.0, and is used in countless apps? 看到它自iOS 2.0以来就已经存在,并且在无数的应用程序中使用了吗?

The process to writing such a slider is incredibly simple, look into UISlider ( https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISlider_Class/ ) and then use the float value from the slider to set the volume. 编写此类滑块的过程非常简单,请查看UISliderhttps://developer.apple.com/library/ios/documentation/UIKit/Reference/UISlider_Class/ ),然后使用滑块中的float值来设置体积。

If you do not want to write your own slider, look on GitHub( github.com ) for controls that do this for you. 如果您不想编写自己的滑块,请在GitHub( github.com )上查找为您执行此操作的控件。 After doing a quick search, I found this UISlider subclass that adjusts volume . 快速搜索后,我发现了此UISlider子类可调整volume

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

相关问题 在iOS版Objective-C中,如何在类视图控制器中使用Slider来更改AppDelage中播放的歌曲的音量? - How to have a Slider in a class view controller that changes the volume of a song playing in the AppDelage, in Objective-C for iOS? iOS / objective-c / xcode:在代码中实例化DetailView控制器 - IOS/objective-c/xcode: Instantiate DetailView Controller in Code iOS / xcode / objective-c:如何在注册后实例化视图控制器 - iOS/xcode/objective-c: How to instantiate view controller after signup ios / xcode / objective-c:UIPickerView不显示 - ios/xcode/objective-c: UIPickerView Not Displaying 如何使用iOS和Objective-C / Xcode加速TDD流程 - How to speed up TDD flow with iOS and Objective-C/Xcode 在iOS上弹出特定的控制器| Objective-C的 - Pop to particular controller on iOS | Objective-c 如何从iOS Objective-C中的控制器重绘自定义视图 - how to redraw custom view from the controller in ios objective-c [iOS] [Objective-c]图像选择器传递给下一个控制器 - [iOS][Objective-c] imagepicker to next controller ios / xcode / objective-c:导航到嵌入在导航控制器中的模态视图控制器 - ios/xcode/objective-c: Segue to modal view controller embedded in navigation controller 如何为Objective-C和Swift创建通用iOS库? - How to make an universal iOS library for both Objective-C and Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM