When using Mpmovieplayerviewcontroller in an application, it is sometimes necessary to keep the application in a vertical state while the video player is displayed as a horizontal screen. If you use a forced horizontal screen, the application will not pass the audit, because the method has been banned by Apple. The main code is as follows:
-(void) addvideoviewcontroller{ mpmovieplayerviewcontroller *movieplayerviewcontroller = [[ Mpmovieplayerviewcontroller alloc] init]; MoviePlayerViewController.view.frame = CGRectMake (0, 0, self.view.bounds.size.height, self.view.bounds.size.width); MoviePlayerViewController.view.center = Cgpointmake (SELF.VIEW.BOUNDS.SIZE.WIDTH/2, SELF.VIEW.BOUNDS.SIZE.HEIGHT/2 ); Cgaffinetransform transform = cgaffinetransformmakerotation (M_PI/2); [Movieplayerviewcontroller.view Settransform:transform]; [Self.view AddSubview:moviePlayerViewController.view];}
Mpmovieplayerviewcontroller is added to its parent Viewcontroller by
The Cgaffinetransformmakerotation () method allows the video player to rotate the dimension so that it can be viewed horizontally, such as:
Little Friends! See the problem is not, the status bar shows the two, how to do it?
In fact, in the IOS7 , each Viewcontroller will take a StatusBar, the above StatusBar is the video player with, video player rotation, The status bar also rotates. The StatusBar on the left is the parent of the video player Viewcontroller , because the parent Viewcontroller is not rotated, so it appears on the left. To solve this problem, you need to hide the left side of the StatusBarwhen the player is displayed, and the left side of the StatusBarwhen exiting the player, as follows:
The following two methods are needed in IOS7 :
(1)-(BOOL) Prefersstatusbarhiddenns_available_ios (7_0);
(2)-(void) Setneedsstatusbarappearanceupdatens_available_ios (7_0);
in the parent Viewcontroller -(BOOL) Prefersstatusbarhidden method, the main code is as follows:
-(BOOL) prefersstatusbarhidden{ return ishiddenstatusbar;} -(void) showstatusbar{ ishiddenstatusbar = NO; if ([Self respondstoselector: @selector (setneedsstatusbarappearanceupdate)]) { [self prefersstatusbarhidden]; [Self setneedsstatusbarappearanceupdate];} } -(void) hidestatusbar{ ishiddenstatusbar = YES; if ([Self respondstoselector: @selector (setneedsstatusbarappearanceupdate)]) { [self prefersstatusbarhidden]; [Self setneedsstatusbarappearanceupdate];} }
(1) Ishiddenstatusbar is defined as a variable that determines whether to hide StatusBar
(2)-(void) ShowStatusBar is a custom method that is called when the status bar needs to be displayed
(3)-(void) Hidestatusbar is a custom method that calls the method when it needs to hide the status bar
At this point mpmovieplayerviewcontroller Horizontal screen display function is realized. This is the result of the test passed on the IOS7 ,IOS6 has not found the corresponding method can hide the left side of the status bar, I hope that an expert can tell me the answer.
IOS7 Mpmovieplayerviewcontroller Horizontal Screen display