Three ways to switch between iPhone and screen and play in full screen

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.