IOS UIWebView: the video is played in full screen mode and must be played in Landscape mode. Landscape mode is not supported for a single app. Solution: iosuiwebview

Source: Internet
Author: User

IOS UIWebView: the video is played in full screen mode and must be played in Landscape mode. Landscape mode is not supported for a single app. Solution: iosuiwebview

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 <UIApplicationDelegate>

{

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];

}



How does one set horizontal and vertical screen adaptation for ios?

In the xcode project, you can select whether to use the horizontal or vertical screen for the APP, but the APP can still switch between the horizontal and vertical screens. There are several ways

1. Code method:

C ++ code

-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {
// You can adjust the settings as shown in the following figure to achieve the desired effect. For example, you can only display a horizontal screen, only a vertical screen, or directly return YES, it indicates that rotation in any direction is supported.
Return (interfaceOrientation = UIInterfaceOrientationPortrait );
}

Of course, there are many judgments in this return:

C ++ code

Return (toInterfaceOrientation = UIInterfaceOrientationLandscapeLeft) | (toInterfaceOrientation = UIInterfaceOrientationLandscapeRight );

// In which direction rotation is supported

Return (toInterfaceOrientation = UIInterfaceOrientationPortrait)
| (ToInterfaceOrientation = UIInterfaceOrientationLandscapeLeft)
| (ToInterfaceOrientation = UIInterfaceOrientationLandscapeRight)
| (ToInterfaceOrientation = UIInterfaceOrientationPortraitUpsideDown );

2. You can also perform the following operations in addition to the Code:

It is very easy to set the horizontal and vertical screen display of the application. By default, the new project supports the left horizontal screen, Right horizontal screen, and vertical screen. If you do not want the horizontal screen display, you only need to delete the two items on the horizontal screen in the project configuration file.

Remember that there are three items in Supported interface orientations: items0. If you want to fix the horizontal and vertical screens, please show them items0. If not, delete it. I don't need this items0 when setting the landscape screen. So I deleted it.

The video cannot be played in full screen on my mobile phone. After the video is clicked in full screen, it is still a portrait screen instead of a landscape screen.

The screen is disabled in the settings. Just close it.

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.