2014-10-27 62 views
1

我剛剛更新了應用程序從Xcode 5到Xcode 6沒有任何更改,沒有問題。但是,在iOS 8設備上運行應用程序時,我的自定義mpVolumeView現在的操作系統默認軌道和拇指覆蓋了我的自定義軌道和拇指。自定義mpVolumeView也顯示默認跟蹤和拇指在iOS 8

我爲音量調節不變的代碼是這樣的:

// 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

有沒有人見過這個問題,或者我應該提交錯誤報告??

回答

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); 
    } 
} 
相關問題