码迷,mamicode.com
首页 > 其他好文 > 详细

iPhone 横竖屏切换,全屏播放的三种方式

时间:2016-06-23 12:24:51      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

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

 

iPhone 横竖屏切换,全屏播放的三种方式

标签:

原文地址:http://www.cnblogs.com/Apple2U/p/5610197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!