自定义mpVolumeView还在iOS 8中显示默认轨道和拇指

时间:2014-10-27 23:42:06

标签: ios8 xcode6 mpvolumeview

我刚刚将Xcode 5中的应用更新为Xcode 6,没有任何变化也没有问题。但是,在iOS 8设备上运行应用程序时,我的自定义mpVolumeView现在具有操作系统默认轨道和拇指覆盖我的自定义轨道和拇指。

我未改变音量控制的代码是:

// Set up volume control
[[self mpVolumeView] setBackgroundColor:[UIColor clearColor]];
MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame: [[self mpVolumeView] bounds]];
[[self mpVolumeView] addSubview:myVolumeView];

for (UIView *view in [myVolumeView subviews]) {
    if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) 
    {  // Find the volume view slider
        volumeViewSlider = (UISlider *) view;
    }
}

UIImage *volumeLeftCap = [[UIImage imageNamed:@"volume-left-cap.png"]
     resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 0)];
UIImage *volumeRightCap = [[UIImage imageNamed:@"volume-right-cap.png"]
     resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 16)];
[volumeViewSlider setMinimumTrackImage:volumeLeftCap forState:UIControlStateNormal];
[volumeViewSlider setMaximumTrackImage:volumeRightCap forState:UIControlStateNormal];

// Note: on iOS7 it is necessary to set the thumb image last or the thumb will 
// be drawn under the slider, on iOS6 the order didn't seem to matter.
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) 
{  // iOS 7.0 or greater
    [volumeViewSlider setThumbImage: [UIImage imageNamed:@"thumb-iOS7.png"]
         forState:UIControlStateNormal];
}
else {
    // Earlier versions of iOS...
    [volumeViewSlider setThumbImage: [UIImage imageNamed:@"thumb.png"]
        forState:UIControlStateNormal];
}

,新结果可以在这里看到:

volume control with two tracks and thumbs

有没有人见过这个问题,还是应该提交错误报告?

1 个答案:

答案 0 :(得分:0)

试试这个:


//avoid picture distortion
UIImage *sliderLeftTrackImage = [[UIImage imageNamed: @"slider_top.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];
[self.slid_vol setMinimumTrackImage: sliderLeftTrackImage forState: UIControlStateNormal];
//slider background
[self.slid_vol setMaximumTrackImage:[UIImage imageNamed:@“slider_background.png"] forState:UIControlStateNormal];
[self.slid_vol currentMaximumTrackImage];

[self.slid_vol setThumbImage:[UIImage imageNamed:@"slider_thumb.png"]forState:UIControlStateNormal];
[self.slid_vol addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];

- (void) sliderValueChanged:(id)sender{
    UISlider* control = (UISlider*)sender;
    if(control == self.slid_vol){
        float volume = control.value;
        NSLog(@"volume:%f", volume);
    }
}