[英]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.