这是我在这里的第一个问题,所以如果我在问题的格式上犯了任何错误,我提前道歉。
我的应用程序中有一个设置屏幕,我在其中放置了一个 UISlider 来控制音量,我从 MPVolumeView 获得了这个滑块,如下所示:
- (UISlider *)getSystemVolumeSlider {
UISlider *volumeSlider;
UISlider *designTemplateSlider = [[UISlider alloc] init];
///////volume slider////////////////////////////////
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
//get only the slider
for (id current in volumeView.subviews){
if ([current isKindOfClass:[UISlider class]]) {
volumeSlider = (UISlider *)current;
UIImage *minimumTrackImage = [[designTemplateSlider minimumTrackImageForState:UIControlStateNormal] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
[volumeSlider setMinimumTrackImage:minimumTrackImage forState:UIControlStateNormal];
UIImage *maximumTrackImage = [[designTemplateSlider maximumTrackImageForState:UIControlStateNormal] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
[volumeSlider setMaximumTrackImage:maximumTrackImage forState:UIControlStateNormal];
[volumeSlider setThumbImage:[designTemplateSlider thumbImageForState:UIControlStateNormal] forState:UIControlStateNormal];
Method originalThumbRect = class_getInstanceMethod(NSClassFromString(@"MPVolumeSlider"),
@selector(thumbRectForBounds:trackRect:value:));
Method newThumbRect = class_getInstanceMethod([CustomUISlider class],
@selector(thumbRectForBounds:trackRect:value:));
method_exchangeImplementations(originalThumbRect, newThumbRect);
[volumeSlider setFrame:CGRectMake(0, 0, 120, 27)];
}
}
return volumeSlider;
}
问题是当我更改音频会话(插件耳机或以编程方式)时,滑块会从屏幕上消失。该滑块位于表格视图内,因此如果我再次向下和向上滚动,滑块将再次显示。任何人都知道如何将其保留在屏幕上或为什么会消失?顺便说一句,我使用 AVAudioPlayer 播放声音。提前谢谢。