3

it´s my first question here so I apologize in advance if I commit any mistakes on the format of my question.

I have a settings screen in my app where I placed a UISlider to control the volume, I got this slider from MPVolumeView like this:

- (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;
}

The problem is that when I change the audio session ( either plugin headphones or programaticallly ) the slider just vanishes from the screen. This slider is inside of a table view so if I scroll it down and up again the slider is shown again. Anyone has an idea on how to keep it on screen or why it vanishes? By the way Im using AVAudioPlayer to play the sounds. thx in advance.

1 Answers1

0

It looks like you're using ARC and maybe your instance gets released and the system removes it from its superview.. just a quick thought.

I haven't checked this, but I'd try moving your slider to a property on your class and then assigning it and testing again.

Shaps
  • 91
  • 8