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