IOS 11 implements the app to disable the screen in the state of the page player full screen

Source: Internet
Author: User

Disable the Turn screen is this meaning, in general set device orientation only vertical screen.

The point is to rewrite the following 3 property methods for Uiviewcontroller

The system's full-screen video player is Avfullscreenviewcontroller, but does not expose any APIs, so to modify in the Uiviewcontroller extension

The following is the implementation method in the Uiviewcontroller extension, which determines that only the video player will turn the screen

-(BOOL) shouldautorotate {if([Self iskindofclass:nsclassfromstring (@"Avfullscreenviewcontroller")]) {        returnYES; }        returnNO;}-(Uiinterfaceorientationmask) supportedinterfaceorientations {if([Self iskindofclass:nsclassfromstring (@"Avfullscreenviewcontroller")]) {        returnUiinterfaceorientationmasklandscaperight; }    returnuiinterfaceorientationmaskportrait;}-(uiinterfaceorientation) preferredinterfaceorientationforpresentation {if([Self iskindofclass:nsclassfromstring (@"Avfullscreenviewcontroller")]) {        returnUiinterfaceorientationlandscaperight; }    returnuiinterfaceorientationportrait;}

It's not over, you need to rewrite it in Appdelegate.

-(Uiinterfaceorientationmask) Application: (UIApplication *) application Supportedinterfaceorientationsforwindow: ( Nullable UIWindow *) window Ns_available_ios (6_0) __tvos_prohibited;

This system method. In fact, only need to support vertical screen and the player horizontal screen two states is enough, but that need to add judgment, in the turn screen when the return of different values. So it is more concise to use Uiinterfaceorientationmaskall directly.

-(Uiinterfaceorientationmask) Application: (UIApplication *) application Supportedinterfaceorientationsforwindow: ( UIWindow *) window {    return  uiinterfaceorientationmaskall;}

The next step is to implement logic in a controller that needs to turn on full-screen playback.

add bool variable to determine if the load is complete

@property (nonatomic,assign) BOOL Didwebviewloadok;

Add the following two notifications when initializing

      object: nil]; // go to fullscreen      object: nil]; // Exit Full Screen

Don't forget to remove

-(void) dealloc {    object: nil];     Object : nil];}

WebView's agent

-(void) Webviewdidfinishload: (UIWebView *) webView {    = YES;} -(void) WebView: (UIWebView *) WebView didfailloadwitherror: (nserror *) error {    = NO;}

Implementing notifications

#pragmamark-notification-(void) begainfullscreen{if(!Self.didwebviewloadok) {return; } [[Uidevice Currentdevice] SetValue:@"Uiinterfaceorientationlandscapeleft"Forkey:@"Orientation"]; if([[Uidevice Currentdevice] Respondstoselector: @selector (setorientation:)]) {SEL selector= Nsselectorfromstring (@"setorientation:"); Nsinvocation*invocation =[Nsinvocation Invocationwithmethodsignature:[uidevice instancemethodsignatureforselector:selector];        [Invocation setselector:selector];        [Invocation Settarget:[uidevice Currentdevice]; intval =Uiinterfaceorientationlandscapeleft; [Invocation setargument:&val Atindex:2];    [Invocation invoke]; }}- (void) endfullscreen{if([[Uidevice Currentdevice] Respondstoselector: @selector (setorientation:)]) {SEL selector= Nsselectorfromstring (@"setorientation:"); Nsinvocation*invocation =[Nsinvocation Invocationwithmethodsignature:[uidevice instancemethodsignatureforselector:selector];        [Invocation setselector:selector];        [Invocation Settarget:[uidevice Currentdevice]; intval =uiinterfaceorientationportrait; [Invocation setargument:&val Atindex:2];    [Invocation invoke]; }}

It's done.

IOS 11 implements the app to disable the screen in the state of the page player full 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.