如何动态设置uiview全屏?

时间:2015-01-31 09:15:10

标签: ios objective-c uiview

我有一个有两个子视图的应用程序。我想双击视频视图(顶部一个)使其全屏显示视频。(全屏,我的意思是它应该是横向模式)所以我该怎么办方法-(void)handleTapGesture::(UITapGestureRecognizer*)recognizer?   我想,首先,我应该隐藏状态栏和导航栏;然后旋转视频视图,使其以编程方式左/右横向显示。   BTW,出于某种原因,我必须让我的应用程序只支持肖像模式。原谅我可怕的英语,如果你不清楚地理解我的问题,请发表评论,谢谢。 project build settings

enter image description here

更新: 我已经隐藏了状态栏和导航栏,但是当我将视频视图设置为全屏时,似乎导航栏和状态栏仍然存在,我的视频视图无法移动到屏幕顶部!

 [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self.navigationController.navigationBar setHidden:YES];

[UIView beginAnimations : @"video full screen" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];

self.videoView.frame = self.view.bounds;
moviewGLView.frame = CGRectMake(0, 0, self.videoView.frame.size.width, self.videoView.frame.size.width*3/4);
moviewGLView.center = self.videoView.center;
videoDefault.center = self.videoView.center;
[UIView commitAnimations];

1 个答案:

答案 0 :(得分:0)

在ViewDidLoad()方法中添加此代码

UITapGestureRecognizer *tapOnTopView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(makeTopViewFullScreen)];
tapOnTopView.numberOfTapsRequired = 1;
[topView addGestureRecognizer:tapOnTopView];

添加以下功能

-(void)makeTopViewFullScreen
{
   [UIView animateWithDuration:0.3 
           animation:^
                   {
                       topViewHeightConstraint = self.view.frame.size.height;
                       bottomViewHeightConstraint = 0;
                       [self layoutIfNeeded];
                   }
           completion:^
                   {
                       //your code to rotate the topView
                   }
}

请注意,topViewHeightConstraint和bottomViewHeightConstraint应该是IB中连接的插座。

希望有所帮助,如果您需要更多帮助,请告诉我。