IOS UIWebView Full screen playback video, need horizontal screen, single app does not support horizontal screen, solution

Source: Internet
Author: User

Originalhttp://blog.csdn.net/alincexiaohao/article/details/39294523

Reference blog:

UIWebView video playback screen automatically rotation, the app does not support rotation but a certain page need to rotate, etc.

Capturing full-screen playback events when playing video with UIWebView

iOS two ways to force a screen to rotate

IOS: Screen rotation and transform

When using UIWebView to play video, think of the video should be able to rotate playback. But the app itself does not support rotation, so the code is recorded as follows, the extension of the answer is: all the pages you want to automatically rotate the page can be used this way. Don't say too much nonsense, the code is as follows:

First, the proxy settings in the Appdelegate, this method system in the screen rotation and other times will be automatically called, not too much worry about the timing of the call:

Preparing for the rotation of the video

-(Nsuinteger) Application: ( UIApplication *) Application Supportedinterfaceorientationsforwindow: ( UIWindow *) window {

if (_isfull)

return uiinterfaceorientationmaskall;

return uiinterfaceorientationmaskportrait;

}

The above code is: set the global variable _isfull of an app, change the global variable and send the corresponding notification (notification below) where the screen rotation is needed, and automatically call the method above to rotate the screen.

The. h code is as follows:

@interface Appdelegate:uiresponder < uiapplicationdelegate >

{

BOOL _isfull; Whether full screen

}

@property (nonatomic) BOOL isfull;

The above has already set the required transformation code, the following is to use the notification when the need to rotate the screen when the system automatically call the above code:

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (videostarted:) Name: @ "Uimovieplayercontr Ollerdidenterfullscreennotification "Object:nil"; The player is about to play notifications

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (videofinished:) Name: @ "Uimovieplayercont Rollerdidexitfullscreennotification "Object:nil"; Player is about to exit notification

The above sends two notifications, respectively: Uimovieplayercontrollerdidenterfullscreennotification, Uimovieplayercontrollerwillexitfullscreennotification, I'm using these two methods, some online says using Uimovieplayercontroller Didexitfullscreennotification this notice, but I use it to find no, should use willexit this notice. The code after the notification is as follows:

After the above method executes, the system invokes the method written in Appdelegate, which changes the direction of the screen support by changing the parameters of the isfull.

Notification method #pragma mark calls the video

Notification method #pragma mark calls the video

-(void) videostarted: ( Nsnotification *) Notification {//start playback

Appdelegate * appdelegate = [[UIApplication sharedapplication] delegate];

Appdelegate. Isfull = YES;

}

-(void) videofinished: ( Nsnotification *) Notification {//finish playback

Appdelegate *appdelegate = [[UIApplication sharedapplication] delegate];

Appdelegate. Isfull = NO;

if ([[Uidevice Currentdevice] Respondstoselector: @selector (setorientation:)]) {

SEL selector = nsselectorfromstring (@ "setorientation:");

Nsinvocation *invocation = [nsinvocation invocationwithmethodsignature: [Uidevice instancemethodsignatureforselector : selector]];

[Invocation setselector:selector];

[Invocation settarget: [Uidevice Currentdevice]];

int val = uiinterfaceorientationportrait;

[Invocation setargument: &val Atindex:2];

[Invocation invoke];

}

NSLog (@ "videofinished%@", Self.view.window.rootViewController.view);

//

NSLog (@ "A = =%f", SELF.VIEW.WINDOW.ROOTVIEWCONTROLLER.VIEW.TRANSFORM.A);

NSLog (@ "b = =%f", self.view.window.rootviewcontroller.view.transform.b);

NSLog (@ "c = =%f", SELF.VIEW.WINDOW.ROOTVIEWCONTROLLER.VIEW.TRANSFORM.C);

NSLog (@ "D = =%f", SELF.VIEW.WINDOW.ROOTVIEWCONTROLLER.VIEW.TRANSFORM.D);

if (self.view.window.rootviewcontroller.view.transform.c = = 1 | | SELF.VIEW.WINDOW.ROOTVIEWCONTROLLER.VIEW.TRANSFORM.C = =-1) {

Cgaffinetransform transform;

Set Rotation degree

Transform = Cgaffinetransformrotate (Self.view.window.rootViewController.view.transform, M_PI/2);

Transform = cgaffinetransformidentity;

[UIView beginanimations:@ "rotate" context:nil];

[UIView setanimationduration:0.1];

[UIView setanimationdelegate:self];

[Self.view.window.rootViewController.view Settransform:transform];

[UIView commitanimations];

//

Self.view.window.rootViewController.view.frame = CGRectMake (0, 0, [UIScreen mainscreen].bounds.size.width, [Uisc Reen mainscreen].bounds.size.height);

//    }

//

[[UIApplication sharedapplication] Setstatusbarorientation:uiinterfaceorientationlandscapeleft Animated:NO];

IOS UIWebView Full screen playback video, need horizontal screen, single app does not support horizontal screen, solution

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.