ScreenRotate icon indicating copy to clipboard operation
ScreenRotate copied to clipboard

UITabBarController 全屏问题

Open coderchou opened this issue 5 years ago • 4 comments

如果window的根控制器为UITabBarController,这种实现方式会有比较大的问题,present出来的全屏控制器,dismiss的时会有错误发生,播放view不能正确添加到原来的父view上,而是错误的添加到 UITabBarController的view上。

  • UIViewControllerAnimatedTransitioning 协议- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext 方法中。
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{
    //转场过渡的容器view
    UIView *containerView = [transitionContext containerView];
    
    //ToVC, 如果跟控制器为UITabBarController ,dismiss时,获取到的是一个 UITabBarController。
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    
    toViewController.view.frame = containerView.bounds;
    //    toViewController.view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
    [containerView addSubview:toViewController.view];
    
    //FromVC
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    fromViewController.view.frame = containerView.bounds;
    
    NSLog(@"containerView %@,toViewController %@, fromViewController %@",containerView,toViewController,fromViewController);

    [containerView addSubview:fromViewController.view];
  }

  • 尝试过修改 modalPresentationStyle值,但是经过测试,为了对原来的app结构不产生比较大的影响,modalPresentationStyle 还是设置为 UIModalPresentationFullScreen 最合适,只是在dismiss的时候,要做一些比较特殊的判断。

coderchou avatar Jan 06 '20 12:01 coderchou

根据作者的思路,我实现了一种比较稳定的横竖屏切换的方案,没用到任何UIKit过期方法,实现了类似优酷视频app爱奇艺视频app横竖屏切换的效果,真香 ! 在此感谢作者的分享!

coderchou avatar Jan 15 '20 08:01 coderchou

@coderchou 你好,你的方案可以给下参考代码,想学习,谢谢了

tasselx avatar Jan 18 '21 02:01 tasselx

@coderchou 你好,你的方案可以给下参考代码,想学习,谢谢了

present控制器 实现横竖屏切换的方式在简单的页面可以实现播放需求,但是如果播放器页面包含有tableView,在切换到横屏时,tableView会上下跳动,cell布局也会出现错乱的情况,特别是如果要在cell上实现横竖屏播放,tableView跳动会更加明显,我没有找到原因。 最后项目采用了另外一种横竖屏切换的方式,通过一个隐藏的window来控制屏幕的方向,可以参考下 ZFPlayer的实现方式。

coderchou avatar Jan 20 '21 01:01 coderchou

@coderchou 你好,你的方案可以给下参考代码,想学习,谢谢了

present控制器 实现横竖屏切换的方式在简单的页面可以实现播放需求,但是如果播放器页面包含有tableView,在切换到横屏时,tableView会上下跳动,cell布局也会出现错乱的情况,特别是如果要在cell上实现横竖屏播放,tableView跳动会更加明显,我没有找到原因。 最后项目采用了另外一种横竖屏切换的方式,通过一个隐藏的window来控制屏幕的方向,可以参考下 ZFPlayer的实现方式。

好的,谢谢

tasselx avatar Jan 20 '21 06:01 tasselx