IOS UIWebView: the video is played in full screen mode and must be played on a horizontal screen. horizontal screen is not supported for a single app. solution:

Source: Internet
Author: User

IOS UIWebView: the video is played in full screen mode and must be played on a horizontal screen. horizontal screen is not supported for a single app. solution:

Refer to blog:

In UIWebView, the video playback screen is automatically rotated. The app does not support rotation, but a page needs to be rotated.

Capture full-screen playback events when playing a video using UIWebView

How to forcibly rotate two screens in iOS

IOS: screen rotation and Transform


When you use UIWebView to play a video, you should think that the video should be capable of rotating playback. However, the app itself does not support rotation, so the code record is as follows. The answer is: This method can be used for all pages that you want to automatically rotate pages. The Code is as follows:

First, set proxy in appDelegate. The system will automatically call this method when the screen is rotated, so there is no need to worry about the call time:

// Prepared for video Rotation

-(NSUInteger) application :( UIApplication *) application supportedInterfaceOrientationsForWindow :( UIWindow *) window {

If (_ isFull)

ReturnUIInterfaceOrientationMaskAll;

ReturnUIInterfaceOrientationMaskPortrait;

}


The code above is: set the global variable _ isFull of an app, change the global variable where the screen needs to be rotated, and send the corresponding notification (the notification is shown below ), the above method is automatically called to rotate the screen.

The. h code is as follows:

@ Interface AppDelegate: UIResponder

{

BOOL _ isFull; // whether to display the full screen

}


@ Property (nonatomic) BOOL isFull;

The required code has been set up above. The following is how to use the notification to automatically call the above Code when the screen needs to be rotated:

[[Nsnotifcencenterdefacenter] addObserver: selfselector: @ selector (videoStarted :) name: @ "UIMoviePlayerControllerDidEnterFullscreenNotification" object: nil]; // notification that the player is about to play


[[Nsnotifcencenterdefacenter] addObserver: selfselector: @ selector (videoFinished :) name: @ "UIMoviePlayerControllerDidExitFullscreenNotification" object: nil]; // notification that the player is about to exit


Two notifications are sent above: UIMoviePlayerControllerDidEnterFullscreenNotification and UIMoviePlayerControllerWillExitFullscreenNotification. I use these two methods. Some online users say that using the notification will fail, use the WillExit notification. The code after the notification is as follows:

After the preceding method is executed, the system calls the method first written in appDelegate to change the orientation of the screen support by changing the isFull parameter.

# Pragma mark calls the video notification method


# Pragma mark calls the video notification method

-(Void) videoStarted :( NSNotification *) notification {// start playing

AppDelegate * appDelegate = [[UIApplicationsharedApplication] delegate];

AppDelegate. isFull = YES;

}



-(Void) videoFinished :( NSNotification *) notification {// finish playing

AppDelegate * appDelegate = [[UIApplicationsharedApplication] delegate];

AppDelegate. isFull = NO;

If ([[UIDevice currentDevice] respondsToSelector: @ selector (setOrientation :)]) {

SEL selector = NSSelectorFromString (@ "setOrientation :");

NSInvocation * invocation = [NSInvocationinvocationWithMethodSignature: [UIDeviceinstanceMethodSignatureForSelector: selector];

[InvocationsetSelector: selector];

[InvocationsetTarget: [UIDevicecurrentDevice];

Int val = UIInterfaceOrientationPortrait;

[InvocationsetArgument: & valatIndex: 2];

[Invocationinvoke];

}

// NSLog (@ "videoFinished % @", self. view. window. rootViewController. view );

//

// NSLog (@ "a = % f", self. view. window. rootViewController. view. transform. );

// 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 the 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, [UIScreen mainScreen]. bounds. size. height );

//}

//

// [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated: NO];

}


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.