zoukankan      html  css  js  c++  java
  • webView中播放视频时自动旋转

     在实际生活应用中,我们希望用户在点击视频时一打开的时候就自动全屏播放,达到更加绚丽的视觉体验效果;

    ****** Appdelegate.h ** 类中***** 

    #import <UIKit/UIKit.h> 

    @interface AppDelegate : UIResponder <UIApplicationDelegate>

    @property (strong, nonatomic) UIWindow *window;

    @property(nonatomic,assign)BOOL isFull;///<是否允许自动旋转

    @end

     

    》》》Appdelegate .m 文件

    - (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(@"退出播放视频了");

        app.isFull=NO;

        

        /**

         下边方法的使用场景:

         如果点击视频,自动旋转为横屏播放状态,点击完成按钮,需要是程序变为竖屏状态,需要下边的代码

         */

        UIViewController *vc = [[UIViewController alloc]init];

        [self presentViewController:vc animated:NO completion:nil];

        [vc dismissViewControllerAnimated:NO completion:nil];

        

    }

    -(void)playerWillShowFullScreen:(id)sender{

        NSLog(@"播放视频了");

        app.isFull=YES;

    }

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any 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 that can be recreated.

    }

    - (void)webViewDidFinishLoad:(UIWebView *)webView{

        

        

        //通知写在这里是因为网页加载完成但是没有播放视频,也会调用playerWillExitFullscreen方法

        

        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIWindowDidBecomeHiddenNotification object:nil];

        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIWindowDidBecomeVisibleNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerWillExitFullscreen:) name:UIWindowDidBecomeHiddenNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerWillShowFullScreen:) name:UIWindowDidBecomeVisibleNotification object:nil];

        

     

    }

    @end

  • 相关阅读:
    Markdown语法入门
    Android开发——绘图基础
    数据结构(java版)学习笔记(三)——线性表之单链表
    数据结构(java版)学习笔记(二)——线性表之顺序表
    数据结构(java版)学习笔记(一)——线性表
    优化电脑方法收集(一)——加内存系统没变化?改几项注册表再感受下
    数据结构(java版)学习笔记(序章)
    基础:从概念理解Lucene的Index(索引)文档模型
    lucene之排序、设置权重、优化、分布式搜索(转)
    Lucene提供的条件判断查询
  • 原文地址:https://www.cnblogs.com/zero-zql/p/4809332.html
Copyright © 2011-2022 走看看