zoukankan      html  css  js  c++  java
  • iPhone 横竖屏切换,全屏播放的三种方式

    1. 调用系统自带的强制屏幕旋转不过还得在AppDelegate中重写下面方法

    - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        // 0:竖屏,1:单向横屏,2:双向横屏
        if (self.httpConnect.SupportedOrientation==0) {
               return UIInterfaceOrientationMaskPortrait;
        }
        else if (self.httpConnect.SupportedOrientation==1){
            return  UIInterfaceOrientationMaskLandscapeRight;
        }
        else{
            return UIInterfaceOrientationMaskAllButUpsideDown;
        }
    }

     

    在Viewcontroller中添加下面方法

    -(BOOL)shouldAutorotate
    {
        return NO;
    }

    - (void)hideNavigationAndTabBar:(BOOL)state {

        [self.navigationController.navigationBar setHidden: state];   

       [self.tabBarController.tabBar setHidden: state];

        [[UIApplication sharedApplication] setStatusBarHidden:state];

    }

    - (void)gotoFullScreenMode {
        
        self.movieView.frame = CGRectMake(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);
        
        [self hideNavigationAndTabBar:YES];
        self.httpConnect.SupportedOrientation = 1;
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeRight] forKey:@"orientation"];
    }
    
    - (void)backToPortraitMode {
        
        [UIView animateWithDuration:0.2 animations:^{
            
            self.httpConnect.SupportedOrientation = 0;
            [self hideNavigationAndTabBar:NO];
            
            [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
        } completion:nil];
    }

    2. 全屏播放利用[UIApplication sharedApplication].keyWindow,主要代码如下

    //不过这种方式麻烦一点,全屏时把movieView从self.view中移到keyWindow当中去;退回全屏时又得把movieView从keyWindow中加到movieView中去,还得重新考虑布局,不推荐这种方式;

    iOS8 之后 [UIScreen bounds] 的宽高会随屏幕方向改变

    • [UIScreen bounds] now interface-oriented
    • [UIScreen applicationFrame]  now interface-oriented
    #define AppKeyWindow ([UIApplication sharedApplication].keyWindow)
    - (void) gotoPlayVideoInFullScreen {
        
        [[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
        
        [AppKeyWindow addSubview: self.movieView];
        self.movieView.transform = CGAffineTransformMakeRotation(M_PI_2);
        self.movieView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    }
    
    - (void)backToNormalState {
        
        [[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation: UIStatusBarAnimationSlide];
        self.movieView.transform = CGAffineTransformIdentity;
        [self.movieView removeFromSuperview];
        
        [self.view addSubview:self.movieView];
    }

    3. 第三种最方便快捷的,直接对self.view进行动画旋转,代码如下

    - (void)gotoPlayVideoInLandscapeMode{
    
        [self hideNavigationAndTabBar:YES];
        self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
        CGRect frame = [UIScreen mainScreen].applicationFrame;
        self.view.bounds = CGRectMake(0, 0, frame.size.height, frame.size.width);
    }
    
    - (void)gotoPlayVideoInPortraitMode {
        
        self.view.transform = CGAffineTransformIdentity;
        [self hideNavigationAndTabBar:NO];
        [self.view layoutIfNeeded];
    }
    
    - (void)hideNavigationAndTabBar:(BOOL)state {
        
        [self.navigationController.navigationBar setHidden: state];
        [self.tabBarController.tabBar setHidden: state];
        [[UIApplication sharedApplication] setStatusBarHidden:state];
    }

  • 相关阅读:
    【Java EE 学习 21 上】【其它类型的监听器】【使用HttpSessionActivationListener监听session的活化和钝化】
    【Java EE 学习 20】【使用过滤器实现登陆验证、权限认证】【观察者模式和监听器(使用监听器实现统计在线IP、登录IP 、踢人功能)】
    【Java EE 学习 19】【使用过滤器实现全站压缩】【使用ThreadLocal模式解决跨DAO事务回滚问题】
    【stut 逆置正整数】
    【JAVA使用XPath、DOM4J解析XML文件,实现对XML文件的CRUD操作】
    【JAVA与DOM4J实现对XML文档的CRUD操作】
    【JAVA解析XML文件实现CRUD操作】
    【JAVA与XML、dtd约束、Schema约束】
    【JAVA正则表达式综合练习】
    【JAVA正则表达式】
  • 原文地址:https://www.cnblogs.com/Apple2U/p/5610197.html
Copyright © 2011-2022 走看看