首页 文章

UIViewController和旋转的模态表示

提问于
浏览
0

所以我的问题看起来像这样:

这是表示视图控制器的方法:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

    if((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
       || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) && self.interfaceShouldRotate) {
        if(self.videoFullscreen == nil) {
            self.videoFullscreen = [self.storyboard instantiateViewControllerWithIdentifier:videoFullscreenController];
            self.videoFullscreen.delegate = self;
        }
        [self.videoFullscreen setVideoView:self.matchVideoView.containerViewForVideo];
        [UIApplication sharedApplication].statusBarHidden = YES;
        [self presentViewController:self.videoFullscreen animated:YES completion:nil];
    }
}

我的想法是通过呈现 UIViewController 以横向模式呈现视频播放器,并使用视频播放器视图在此控制器中设置视图:

- (void)setVideoView:(UIView *)videoView {
NSParameterAssert(videoView);

_videoView = videoView;
[self.view addSubview:_videoView];
_videoView.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *views = @{@"video":_videoView};

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[video]|"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:views]];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[video]|"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:views]];

}

这是委托方法,通知根视图控制器它将被解雇,并且视频播放器应该以纵向方向再次嵌入 .

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait
       || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        [self.delegate fullscreenViewControllerdidRotateToPortrait:self];
    }
}

委托方法执行此操作:

- (void) removeViewAndDismissFullscreenVideoController {
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
    self.matchVideoView.containerViewForVideo = self.videoFullscreen.videoView;
    [UIApplication sharedApplication].statusBarHidden = NO;
}

- (NSUInteger)supportedInterfaceOrientations- (BOOL)shouldAutorotate 在自定义 UINavigationController 中设置 . . 应用程序仅在纵向模式下 . 播放视频时,通知开关支持 UIInterfaceOrientationMaskAll 的方向,用户可以使用嵌入的视频旋转屏幕 . 当设备旋转为横向时,视频播放器将移至全屏 .

那么问题出在哪里?在iOS 8上它运行良好,但在iOS 7中,当视频播放器控制器被解除时,带有嵌入式播放器的控制器保持横向模式,但只能查看因为 - (void)viewDidAppear:(BOOL)animated 当我检查 self.interfaceOrientation UIViewController 处于纵向模式时(视图是横向模式) . 一切都与Autolayout有关 . 任何想法如何找到问题的原因并解决它?

edit:

以下答案 . 它必须位于View Controller中,在子视图中嵌入了视频播放器,当在横向视频中移动视频控制器视图时 . 此外,这也不起作用 .

Solution:

我已经移动了代码进行纵向旋转,将全屏视频解除为didRotate(仅适用于iOS7)并进行自定义转换 . 那解决了问题 .

1 回答

  • 1

    我认为不需要在该类中管理它只需在AppDelegate方法中编写一些代码来仅旋转单个视图 . 如下所示

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    
        if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone )
        {
            if ([[self.window.rootViewController presentedViewController]
                 isKindOfClass:[MPMoviePlayerViewController class]]) {
                return UIInterfaceOrientationMaskAllButUpsideDown;
            }
    
            return UIInterfaceOrientationMaskPortrait;
        }
        return UIInterfaceOrientationMaskAll;
    }
    

    该代码告诉“MPMoviePlayerViewController”显示屏幕旋转设置为启用,否则仅设置为纵向模式 .

    我希望它会对你有所帮助 .

相关问题