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];
}

 

转载于:https://www.cnblogs.com/Apple2U/p/5610197.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值