iOS development--full-screen playback of the player without support for horizontal screen

Source: Internet
Author: User

When using MPMoviePlayerController to implement the player playback, found that cannot play full-screen, the original is because the project does not support horizontal screen, the support for horizontal screen is OK, but other pages do not support horizontal screen, this method will not work.

On the internet to find a lot of information, many are abandoned after iOS 6, are useless, below I will introduce, in the case of not support horizontal screen, to achieve full-screen video player playback.

1.

First in AppDelegate.h definition @property (nonatomic, assign) BOOL allowrotation; Whether the marker can be rotated

2.

At the same time in the APPDELEGATE.M implementation of this method, you need to return a support screen steering, make a simple judgment, whether to support the screen, or return uiinterfaceorientationmaskall, otherwise return uiinterfaceorientationmaskport Rait. The return is an enumeration in which the meanings of various values are not introduced here.

-(Uiinterfaceorientationmask) Application: (UIApplication *) application Supportedinterfaceorientationsforwindow: ( UIWindow *) Nowwindow {

Non-supported screen

if (_allowrotation) {

return uiinterfaceorientationmaskall;

} else{

return uiinterfaceorientationmaskportrait;

}

}

3.

In a full-screen controller need to set Allowrotation to Yes, then you can achieve the automatic conversion of the screen.

Appdelegate *appdelegate = [UIApplication sharedapplication].delegate;

Appdelegate.allowrotation = YES;

4.

Note that when you return to a different interface, you set Allowrotation to No.

Setting does not support horizontal screen

Appdelegate *appdelegate = [UIApplication sharedapplication].delegate;

Appdelegate.allowrotation = NO;

5.

There is another problem to note, when the horizontal screen, the navigation bar may appear, if you press the Back button or go to other interface buttons, to the other interface is also a horizontal screen. So to play the video in the horizontal screen, hide the navigation bar. I use the notice to hide the navigation bar, there are other ways to do so, welcome to put forward.

First, go back to the protocol proxy method in the APPDELEGATE.M file to add the notification

Add notification horizontal screen does not appear navigation bar

[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "Hidenav" object:nil];

Then accept the notification in the controller of the player that requires a horizontal screen, and then hide the navigation bar when the horizontal screen is used. Here need to do a screen of the judge, I am based on the width of the screen to judge, as well as a lot of other methods can be achieved.

Accept notification to determine if the navigation bar is hidden

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (Hiden) name:@ "Hidenav" object:nil];

#pragma mark-Accept notification to determine if the navigation bar is hidden

-(void) hiden{

if ([UIScreen mainscreen].bounds.size.width > [UIScreen mainscreen].bounds.size.height) {

Horizontal screen Hide

Self.navigationController.navigationBarHidden = YES;

}else{

Vertical screen Display

Self.navigationController.navigationBarHidden = NO;

}

}

OK, this will solve the problem when the horizontal screen is not supported, you can play the full screen function, I hope to help everyone.

iOS development--full-screen playback of the player without support for horizontal screen

Related Article

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.