[英]Modal presentation of UIViewController and rotation
So my problem looks like this: 所以我的问题看起来像这样:
This is method for presentation view controller: 这是表示视图控制器的方法:
- (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];
}
}
My idea is to present Video Player in landscape mode by presenting UIViewController
and set view in this controller with Video Player view: 我的想法是通过呈现UIViewController
并以Video Player视图在此控制器中设置视图,以横向模式呈现Video Player:
- (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]];
} }
This is delegate method that informs root view controller that it will dismiss and Video Player should be embeded again in portrait orientation. 这是一个委托方法,它通知根视图控制器将其关闭,并且应将Video Player重新以纵向方向嵌入。
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if(toInterfaceOrientation == UIInterfaceOrientationPortrait
|| toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[self.delegate fullscreenViewControllerdidRotateToPortrait:self];
}
}
Delegate method does this: 委托方法执行此操作:
- (void) removeViewAndDismissFullscreenVideoController {
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
self.matchVideoView.containerViewForVideo = self.videoFullscreen.videoView;
[UIApplication sharedApplication].statusBarHidden = NO;
}
- (NSUInteger)supportedInterfaceOrientations
and - (BOOL)shouldAutorotate
are set in custom UINavigationController
.Whole app is in portrait mode only. - (NSUInteger)supportedInterfaceOrientations
InterfaceOrientations和- (BOOL)shouldAutorotate
在自定义UINavigationController
中设置。整个应用程序仅处于纵向模式。 When video is playing, notification switch supported orientation to UIInterfaceOrientationMaskAll
and user can rotate screen with embeded Video. 播放视频时,通知将支持的方向切换为UIInterfaceOrientationMaskAll
并且用户可以旋转嵌入视频的屏幕。 When device will rotate to landscape, video player moves to full screen. 当设备旋转到横向时,视频播放器将移至全屏。
So where is problem? 那么问题出在哪里呢? On iOS 8 it works good, but in iOS 7 when video player controller is dismissed, controller with embeded player stays in landscape mode, but only view because in - (void)viewDidAppear:(BOOL)animated
when I check self.interfaceOrientation
UIViewController
is in portrait mode (view is landscape mode). 在iOS 8上它运行良好,但是在iOS 7中,当视频播放器控制器被关闭时,具有嵌入式播放器的控制器将保持横向模式,但只能查看,因为当我检查self.interfaceOrientation
UIViewController
为- (void)viewDidAppear:(BOOL)animated
时是- (void)viewDidAppear:(BOOL)animated
在纵向模式下(视图为横向模式)。 Everything is with Autolayout. 一切都与自动排版有关。 Any idea how to find cause of problem and fix it? 任何想法如何找到问题的原因并解决它?
edit: 编辑:
To the answer below. 到下面的答案。 It must be in View Controller that has embeded Video player in subview, when in landscape VideoView is moved to presented View Controller view. 当横向移动VideoView到显示的View Controller视图时,它必须在将Video Player嵌入子视图的View Controller中。 Besides, this doesn't work also. 此外,这也不起作用。
Solution: 解:
I've moved code for portrait rotation, that dismiss fullscreen to didRotate (only for iOS7) and make custom transition. 我已经移动了用于肖像旋转的代码,将全屏显示为didRotate(仅适用于iOS7)并进行了自定义过渡。 That solve problem. 那解决了问题。
I think no need for manage it in that class just write some code in AppDelegate methods for rotate single view only. 我认为无需在该类中对其进行管理,只需在AppDelegate方法中编写一些代码即可(仅用于旋转单个视图)。 as like follows 如下
-(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;
}
that code tells "MPMoviePlayerViewController" is showing rotation of screen set as enable otherwise set as portrait mode only. 该代码告诉“ MPMoviePlayerViewController”正在显示屏幕旋转为启用状态,否则仅设置为纵向模式。
I hope it will helps you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.