So I have an iOS7 app that I'm using a MPVolumeView
in so the user can control the volume level. I have the route button hidden on this particular MPVolumeView
and use another MPVolumeView
with the slider disabled as my AirPlay icon.
My app supports both Portrait and landscape orientations, and the volume slider is a different width in these two different modes.
If the view gets initialized in Landscape mode first, then the MPVolumeView
will resize itself correctly.
However, when the view gets initialized in Portrait mode and then I rotate to Landscape mode, EVERYTHING else in the app gets resized/moved except the MPVolumeView
only gets moved, and it doesn't get shorter like it should.
I am using custom images on the MPVolumeView
, and if I remove the custom images for the track, this problem goes away.
Here is the code used to initialize the MPVolumeView
self.volumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
self.volumeView.showsRouteButton = NO;
self.volumeView.layer.borderColor = [[UIColor redColor] CGColor];
self.volumeView.layer.borderWidth = 1.0f;
if (AT_LEAST_IOS7) {
// TODO: BUGBUG iOS7 doesn't redraw this MPVolumeView correctly when it's frame changes (i.e. we rotate to the portrait view).
// These images simply make the bar a little thicker than the standard thickness (to match the iOS7 music app) but it's not redrawing
// correctly so we are going to have to live with a slightly thinner bar.
[self.volumeView setMaximumVolumeSliderImage:[UIImage imageNamed:@"volume_bar_max"] forState:UIControlStateNormal];
[self.volumeView setMinimumVolumeSliderImage:[UIImage imageNamed:@"volume_bar_min"] forState:UIControlStateNormal];
[self.volumeView setVolumeThumbImage:[UIImage imageNamed:@"volume_scrubber"] forState:UIControlStateNormal];
}
[self addSubview:self.volumeView];
And in layoutSubviews I am repositioning/scaling it's frame:
self.volumeView.frame = CGRectIntegral(CGRectMake(controlsLeft + kEdgeToSliderSideWidth,
volumeTop,
controlsWidth - (2 * kEdgeToSliderSideWidth),
volumeSize.height));
Here is what it looks like when the view starts out in Portrait Mode: (overall width of 640 pixels)
And when it gets rotated to Landscape it ends up looking like this: (overall width of 568 pixels)
Does anybody have any ideas?