Auto-rotate when playing video in WebView

Source: Internet
Author: User
Tags uikit

In real life applications, we want users to click on the video when the opening of the automatic full-screen playback, to achieve a more brilliant visual experience effect;

* * * * * in Appdelegate.h

#import <UIKit/UIKit.h>  

@interface appdelegate: uiresponder <uiapplicationdelegate>

@property (strong, nonatomic) uiwindow *window;

@property(nonatomic,assign)BOOL isfull; < whether automatic rotation is allowed

@end

"" Appdelegate. m file

-(Nsuinteger) Application: (uiapplication *) application Supportedinterfaceorientationsforwindow: (uiwindow *) window

{

if (! _isfull) {

return uiinterfaceorientationmaskportrait;

}Else{

return uiinterfaceorientationmaskallbutupsidedown;

}

}

#import "ViewController.h"

#import "AppDelegate.h"

@interface Viewcontroller () <uiwebviewdelegate>{

appdelegate *app;

}

@end

@implementation Viewcontroller

-(void) dealloc{

[[nsnotificationcenter defaultcenter] removeobserver:self name: Uiwindowdidbecomehiddennotification Object:nil];

[[nsnotificationcenter defaultcenter] removeobserver:self name: Uiwindowdidbecomevisiblenotification Object:nil];

}

-(void) Playerwillexitfullscreen: (ID) sender{

NSLog(@ " quit playing video ");

app. Isfull=NO;

/**

usage Scenarios for the following methods:

If you click on the video , automatically rotate to the horizontal screen playback status , Click the Finish button , need to be the program into a vertical state , need the code below

*/

uiviewcontroller *VC = [[uiviewcontroller alloc]init];

[self presentviewcontroller: VC animated:NO completion:nil];

[VC dismissviewcontrolleranimated:NO completion:nil];

}

-(void) Playerwillshowfullscreen: (ID) sender{

NSLog(@ " play video ");

app. Isfull=YES;

}

-(void) viewdidload {

[Super viewdidload];

additional setup after loading the view, typically from a nib.

self. Title=@ "WebView";

cgrect rect=self. View. Frame;

rect.size.height-=64;

UIWebView *webview=[[uiwebview alloc] initwithframe: rect];

WebView. delegate=self;

[WebView loadrequest: [nsurlrequest requestwithurl: [ nsurl urlwithstring: @ "http://www.tudou.com/albumplay/O8GDpd7v8RA/qTfiUJAEdm0.html" ]];

[self. View addsubview: WebView];

app= (appdelegate *) [uiapplication sharedapplication]. Delegate;

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

//Dispose of any resources, can be recreated.

}

-(void) Webviewdidfinishload: (uiwebview *) webview{

// notifications are written here because the Web page is loaded but no video is played, and the playerwillexitfullscreen method is called

    [[nsnotificationcenter defaultcenter removeobserver: self name: Uiwindowdidbecomehiddennotification object: Nil

    [[nsnotificationcenter defaultcenter removeobserver: self name: Uiwindowdidbecomevisiblenotification object: nil]

    [[nsnotificationcenter defaultcenter addobserver: self selector: @selector Span class= "S4" > (Playerwillexitfullscreen:) name:uiwindowdidbecomehiddennotification span class= "s2" >object:nil];

[[nsnotificationcenter defaultcenter] addobserver:self selector:@ Selector(playerwillshowfullscreen:) name:uiwindowdidbecomevisiblenotification object:nil];

}

@end

Auto-rotate when playing video in WebView

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.