uiview - MPVolumeView doesn't redraw correctly in iOS 7 -
so have ios7 app i'm using mpvolumeview
in user can control volume level. have route button hidden on particular mpvolumeview
, use mpvolumeview
slider disabled airplay icon.
my app supports both portrait , landscape orientations, , volume slider different width in these 2 different modes.
if view gets initialized in landscape mode first, mpvolumeview
resize correctly.
however, when view gets initialized in portrait mode , rotate landscape mode, else in app gets resized/moved except mpvolumeview
gets moved, , doesn't shorter should.
i using custom images on mpvolumeview
, , if remove custom images track, problem goes away.
here code used initialize 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 mpvolumeview correctly when it's frame changes (i.e. rotate portrait view). // these images make bar little thicker standard thickness (to match ios7 music app) it's not redrawing // correctly going have live 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 repositioning/scaling it's frame:
self.volumeview.frame = cgrectintegral(cgrectmake(controlsleft + kedgetoslidersidewidth, volumetop, controlswidth - (2 * kedgetoslidersidewidth), volumesize.height));
here looks when view starts out in portrait mode: (overall width of 640 pixels)
and when gets rotated landscape ends looking this: (overall width of 568 pixels)
does have ideas?
i'm experiencing same issue. current workaround destroy , re-add slider after screen rotation:
- (void)didrotatefrominterfaceorientation:(uiinterfaceorientation)frominterfaceorientation { //remove old view (uiview *subview in self.volumeviewcontainer.subviews) [subview removefromsuperview]; //recreate uiimage *slider = [[uiimage imagenamed:@"slider"] resizableimagewithcapinsets:uiedgeinsetsmake(0.0, 15.0, 0.0, 15.0)]; uiimage *knobimage = [uiimage imagenamed:@"slider_knob"]; mpvolumeview *volumeview = [[[mpvolumeview alloc] initwithframe:self.volumeviewcontainer.bounds] autorelease]; [volumeview setminimumvolumesliderimage:slider forstate:uicontrolstatenormal]; [volumeview setmaximumvolumesliderimage:slider forstate:uicontrolstatenormal]; [volumeview setvolumethumbimage:knobimage forstate:uicontrolstatenormal]; [self.volumeviewcontainer addsubview:volumeview]; }
doing there still issue slider still displayed glitches during rotation. that's why render slider image , swap slider said image before rotation takes place:
- (void)willrotatetointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration:(nstimeinterval)duration { //render uiimage uigraphicsbeginimagecontextwithoptions(self.volumeviewcontainer.frame.size, no, 0.0); [self.volumeviewcontainer.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage * img = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); //remove old slider (uiview *subview in self.volumeviewcontainer.subviews) [subview removefromsuperview]; //add uiimageview resizes nicely container view uiimageview *imageview = [[[uiimageview alloc] initwithframe:self.volumeviewcontainer.bounds] autorelease]; imageview.autoresizingmask = uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight; imageview.image = img; [self.volumeviewcontainer addsubview:imageview]; }
i know not real solution, think it's better nothing , hope helps you.
Comments
Post a Comment