简体   繁体   English

ios7-在另一个视图上显示视图控制器,但不全屏显示

[英]ios7 - showing a view controller on top of another but not in full screen

When i press a button on my view controller, i would like to present another controller on top of it, but in the middle and not in full screen. 当我按下视图控制器上的按钮时,我想在其顶部显示另一个控制器,但要在中间而不是全屏显示。

How could i present a controller on top of another controller in such way? 我如何以这种方式将控制器呈现在另一个控制器之上?

If you are trying it on iPad you can always set up a Popover that contains your new view. 如果要在iPad上尝试,则始终可以设置一个包含新视图的Popover。

UIYourNewViewController *vc = [[UIYourNewViewController alloc] init];

UIPopoverController *popVc = [[UIPopoverController alloc] initWithContentViewController:vc];
[popVc setPopoverContentSize:*the size that you want or your resized vc*];
[popVc presentPopoverFromRect:*position of the screen you want to show the popover* inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

With this you will create a Popover of the size of the view of your viewcontroller and you can pop it up in the position that you want. 这样,您将创建一个viewcontroller视图大小的Popover,然后可以将其弹出到所需的位置。 To make sure it works on iPhone also, you should create a category for the UIPopoverController and add this method in the .m 为了确保它也可以在iPhone上使用,您应该为UIPopoverController创建一个类别,然后在.m中添加此方法。

+ (BOOL)_popoversDisabled {
return NO;

} }

Remember to declare the method in the .h of the category. 请记住在类别的.h中声明该方法。

You need to set this property to your controller before presenting it. 您需要在呈现此属性之前将其设置为控制器。

controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:controller animated:YES completion:nil];

Yes it is possible you have to present view controllers view with animation. 是的,可能必须向视图控制器视图显示动画。 Please refer the below code. 请参考下面的代码。 You will get some idea its showing animation from bottom of screen to middle of screen. 您会从屏幕底部到屏幕中间看到一些显示动画的想法。

YourViewController *viewController = [[YourViewController alloc] init];
    [viewController.view setFrame:CGRectMake(0, -(CGRectGetHeight(viewController.view.frame)), CGRectGetWidth(viewController.view.frame), CGRectGetHeight(self.view.frame))];

    [self.view addSubview:viewController.view];
    [UIView animateWithDuration:0.8 animations:^{

        [viewController.view setFrame:CGRectMake(0, 0, CGRectGetWidth(viewController.view.frame), CGRectGetHeight(viewController.view.frame))];

    } completion:^(BOOL finished) {
        [self.navigationController pushViewController:viewController animated:NO];
    }];

In iPhone, presenting a UIViewController is always fullscreen. 在iPhone中,呈现UIViewController始终是全屏的。 On iPad, you can use a UISplitViewController or build a custom container, but the view controllers you present will fill the containers in both a UISplitViewController and custom container controller. 在iPad上,您可以使用UISplitViewController或构建自定义容器,但是您显示的视图控制器将同时填充UISplitViewController和自定义容器控制器中的容器。

To present content on only part of the screen, you can animate a UIView onto your view controller. 要仅在屏幕的一部分上显示内容,可以将UIView设置为视图控制器的动画。 There are ways to present a view controller and still have another view controller show up behind it, but this is not recommended. 有多种方法可以呈现视图控制器,但仍然可以在其后显示另一个视图控制器,但是不建议这样做。

Check out this other question for more information on creating a custom container view controller.. 请查看此其他问题 ,以获取有关创建自定义容器视图控制器的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPad / iOS7:从中呈现“全屏”视图控制器后,“页面”模式视图控制器出现异常行为 - iPad/iOS7: 'Page' modal view controller strange behaviour after presenting 'Full screen' view controller from it 在没有全屏的情况下在另一个视图控制器上显示视图控制器 - Present a view controller on top another one without full screen 在iOS中将视图拆分为另一个全视图控制器 - Split View To another Full View Controller in iOS 将数据从didSelectRowAtIndexPath传递到另一个视图控制器ios7 - passing data from didSelectRowAtIndexPath to another view controller ios7 iOS7 Safari中的全屏模式 - Full Screen mode in iOS7 Safari iOS在UIModalTransitionStylePartialCurl视图控制器上的当前全屏视图 - iOS Present Full Screen view on UIModalTransitionStylePartialCurl View Controller 如何在ios应用程序的相机全屏视图上绘制图片? - how to draw on top of the camera full screen view in an ios app? 以编程方式在“模态对话框”中显示视图控制器显示为全屏 - Showing a view controller in Modal Dialog programmatically is appearing as full screen 在iOS7的视图顶部添加UISearchBar修复程序? - Add UISearchBar fix on top of a View in iOS7? “呈现的视图控制器始终全屏显示”不适用于iOS 7自定义过渡吗? - “presented view controller always full screen” not true for iOS 7 custom transitioning?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM