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