将视图控制器的视图展开到全屏

时间:2013-11-20 10:30:07

标签: ios objective-c uiview uiviewcontroller

我的应用程序中有一个相当复杂的视图控制器层次结构。我目前有一个视图,我想用按钮点击全屏。问题是,因为这个视图位于视图控制器的视图中,只占屏幕的一部分,所以我不能简单地将帧设置为应用程序窗口的大小。我也无法以模态方式呈现视图,因为这会干扰我的其他UI。

帮助解释我的意思:

UIViewController // root view controller
    --> UIViewController
         --> UIViewController
         --> UIViewController
    --> UIViewController
         --> Controller's View <----- // this one
    --> UIViewController

我需要制作上面显示的视图,因为已经在视图控制器中显示以扩展到全屏。

了解这个问题的最佳方法是什么?

2 个答案:

答案 0 :(得分:1)

我正在做一些类似的事情希望这个帮助。我有支持全屏视频的视频播放器。

请参阅此代码,您需要进行更改,因为这只是我的代码的一部分,只是为了说明我是如何做到的。

UIView *rootView =  [[[[[UIApplication sharedApplication] delegate] window] rootViewController] view];
CGRect rect = [myView convertRect: myView.frame toView:rootView];
UIView *interactionView = [[UIView alloc] initWithFrame:rect];
interactionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
[interactionView.layer insertSublayer:myView.layer below:otherView.layer ];// i am using otherView u can use if any or use addSublayer otherwise
myView.layer.frame = rootView.bounds;
interactionView.frame = rootView.bounds;

答案 1 :(得分:0)

 UIView *yourview = yourViewController.view; 

    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:.5];
    yourview.frame = [[UIApplication sharedApplication].windows.lastObject frame];
    [UIView commitAnimations];