1. Invoking the system's own forced screen rotation However, you have to override the following method in Appdelegate
-(Uiinterfaceorientationmask) Application: (UIApplication *) application Supportedinterfaceorientationsforwindow: ( UIWindow *) window{//0: Vertical screen, 1: one-way horizontal screen, 2: Two-way horizontal screen if(self.httpconnect.supportedorientation==0) { returnuiinterfaceorientationmaskportrait; } Else if(self.httpconnect.supportedorientation==1){ returnUiinterfaceorientationmasklandscaperight; } Else{ returnUiinterfaceorientationmaskallbutupsidedown; }}
Add the following method in the Viewcontroller
-(BOOL) shouldautorotate{ return NO;
-(void) Hidenavigationandtabbar: (BOOL) state {
[self. Navigationcontroller. Navigationbar Sethidden: state];
[self. Tabbarcontroller. TabBar Sethidden: state];
[[uiapplication sharedapplication] setstatusbarhidden: state];
}
- (void) Gotofullscreenmode {self.movieView.frame= CGRectMake (0,0, Screen_height, screen_width); [Self hidenavigationandtabbar:yes]; Self.httpConnect.SupportedOrientation=1; [[Uidevice Currentdevice] Setvalue:[nsnumber numberwithinteger:uideviceorientationlandscaperight] ForKey:@"Orientation"];}- (void) Backtoportraitmode {[UIView animatewithduration:0.2animations:^{self.httpConnect.SupportedOrientation=0; [Self hidenavigationandtabbar:no]; [[Uidevice Currentdevice] Setvalue:[nsnumber numberwithinteger:uideviceorientationportrait] ForKey:@"Orientation"]; } Completion:nil];}
2. Full-screen playback using [UIApplication Sharedapplication].keywindow, the main code is as follows
But this is a bit of a hassle, Full screen when the Movieview from the Self.view to move to the Keywindow, back to the full screen when the Movieview from Keywindow to Movieview, but also to reconsider the layout, not recommended this way;
IOS8 after [uiscreen bounds] will change with the screen orientation
- [UIScreen bounds] now interface-oriented
- [UIScreen Applicationframe] Now interface-oriented
#defineAppkeywindow ([UIApplication Sharedapplication].keywindow)-(void) Gotoplayvideoinfullscreen {[[UIApplication sharedapplication]setstatusbarhidden:yes WithAnimation:UIStatusBa Ranimationfade]; [Appkeywindow AddSubview:self.movieView]; Self.movieView.transform=cgaffinetransformmakerotation (m_pi_2); Self.movieView.frame= CGRectMake (0,0, Screen_width, screen_height);}- (void) backtonormalstate {[[UIApplication sharedapplication]setstatusbarhidden:no Withanimation:uistatusbaranimatio Nslide]; Self.movieView.transform=cgaffinetransformidentity; [Self.movieview Removefromsuperview]; [Self.view AddSubview:self.movieView];}
3. The third most convenient and fast, directly to the Self.view animation rotation, the code is as follows
- (void) gotoplayvideoinlandscapemode{[self hidenavigationandtabbar:yes]; Self.view.transform= Cgaffinetransformmakerotation (m_pi/2); CGRect Frame=[UIScreen mainscreen].applicationframe; Self.view.bounds= CGRectMake (0,0, Frame.size.height, frame.size.width);}- (void) Gotoplayvideoinportraitmode {self.view.transform=cgaffinetransformidentity; [Self hidenavigationandtabbar:no]; [Self.view layoutifneeded];}- (void) Hidenavigationandtabbar: (BOOL) state {[Self.navigationController.navigationBar sethidden:state]; [Self.tabBarController.tabBar Sethidden:state]; [[UIApplication sharedapplication] setstatusbarhidden:state];}
Three ways to switch between iPhone and screen and play in full screen