ios - MPVolumeView 仅适用于 iPod

标签 ios iphone ipad

我在我的项目中添加了这样的 MPVolumeview

这是我用于 iPad 的代码。

-(void) 添加音量控制 {

volumeView = [[MPVolumeView alloc] initWithFrame: CGRectMake(780, 33, 150, 40)];


NSArray *tempArray = volumeView.subviews;

for (id current in tempArray)
{
    if ([current isKindOfClass:[UISlider class]])
    {
        UISlider *tempSlider = (UISlider *) current;
        [tempSlider setMaximumTrackTintColor:[UIColor clearColor]];

        CGRect rRect = tempSlider.frame;
        rRect.origin.x = rRect.origin.x + 20;
        tempSlider.frame = rRect;

        UIImage *pMaxTrackImage;
        UIImage *pMinTrackImage;
        UIImage *pThumbImage;

        pMaxTrackImage = [[UIImage imageNamed:@"pgbar_sound_fill_ipad"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
        pMinTrackImage = [[UIImage imageNamed:@"pgbar_sound_bg_ipad"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
        pThumbImage    = [UIImage imageNamed:@"pgbar_sound_thumb_ipad"];

        [tempSlider setMaximumTrackImage:pMaxTrackImage forState:UIControlStateNormal];
        [tempSlider setMinimumTrackImage:pMinTrackImage forState:UIControlStateNormal];
        [tempSlider setThumbImage:pThumbImage forState:UIControlStateNormal];
    }
}

volumeView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;

[self._bottomBar addSubview:volumeView];

在 iPod 中运行应用程序时音量正常,但在 iPhone 和 iPad 中不起作用。

我测试的设备是iPod5和iPhone5C。 我测试的操作系统是 iOS6 和 iOS7。

我已经尝试了几乎所有可用的帮助,但没有一个对我有用。 请提供一些建议/指导。

谢谢,

尼基尔.T

最佳答案

您需要设置这些值setMinimumTrackImagesetMaximumTrackImagesetThumbImage

for (UIView *sv in [volumeSlider subviews])
{
    if ([sv isKindOfClass:[UISlider class]])
    {
        UISlider *slider = (UISlider*) sv;
        [slider setMinimumTrackImage:yourImage forState:UIControlStateNormal];
        [slider setMaximumTrackImage:yourImage forState:UIControlStateNormal];
        [slider setThumbImage:yourImage forState:UIControlStateNormal];
    }
}

关于ios - MPVolumeView 仅适用于 iPod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23761326/

相关文章:

ios - UIButton 的 uiappearance 也会更改 UIBarButton 图像吗?

iphone - 企业 iPad 应用程序分发

iphone - Xcode SDK 中缺少 Pragma Mark

ruby-on-rails - 通过rails向Ipad提供mp4文件的正确方法是什么?

iphone - UILabel 在第 3 代和第 4 代 iPod 上的显示方式有所不同

iphone - 将大量 Sqlite 行加载到 UITableView 中

ios - swift,来自 View Controller 的 UIUserNotificationAction 而不是应用程序委托(delegate)

iphone - iOS应用保护

ios - 收到 GMSServicesException 错误

ios - 一个 Facebook 应用与多个 iOS 应用关联