1

我刚刚将一个应用程序从 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];
}

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

带有两个轨道和拇指的音量控制

有没有人看到这个问题或者我应该提交错误报告?

4

1 回答 1

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);
    }
}
于 2015-07-08T08:10:03.527 回答