xcode UIView 转换在底部呈现模态视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2422119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIView transitions present modal view at the bottom
提问by Dave
I need to display a UIView/UIViewController when the user taps a button and the modal view should appear just like how the key board appears from the bottom bar when you edit text in a UITextField. Using the following code, I get to show it as a pop up.
当用户点击按钮时,我需要显示一个 UIView/UIViewController,并且模态视图应该看起来就像在 UITextField 中编辑文本时键盘从底部栏中的显示方式一样。使用以下代码,我可以将其显示为弹出窗口。
[self presentModalViewController:child animated:YES];
How to make it appear like the keyboard?
如何让它看起来像键盘?
I understad modal views cover the entire screen. But I reallywant a view that covers only half the screen. So, please tell me why this doesn't work
我理解模态视图覆盖整个屏幕。但我真的想要一个只覆盖一半屏幕的视图。所以,请告诉我为什么这不起作用
MyController *controller = [[MyController alloc] initWithNibName:@"MyView" bundle:nil];
CGRect frame = CGRectMake(0,44,768,264);
[controller view].frame = frame;
contoller.delegate = self;
[[self view] addSubView:[controller view]];
[controller release];
I am trying to add a sub view to my current view and make it appear where the keyboard appears.
我正在尝试向当前视图添加一个子视图,并使其出现在键盘出现的位置。
回答by kennytm
Check if your child.modalTransitionStyle == UIModalTransitionStyleCoverVertical
.
检查您的child.modalTransitionStyle == UIModalTransitionStyleCoverVertical
.
(And a model view controller always cover the whole screen. If you just need to cover half of the screen like the keyboard, you need to put the view controller's view as a subview of the main view, then animate it in manually with animation blocks.)
(而且模型视图控制器总是覆盖整个屏幕。如果你只需要像键盘一样覆盖一半的屏幕,你需要把视图控制器的视图作为主视图的子视图,然后用动画块手动动画它.)
回答by kennytm
I know its an old question, but an answer to this is to use a UIActionSheet.
我知道这是一个老问题,但对此的答案是使用 UIActionSheet。
It won't present a View Controller, but you can present custom views that only cover a portion of the screen.
它不会显示视图控制器,但您可以显示仅覆盖屏幕一部分的自定义视图。
Check out this question for more information
查看此问题以获取更多信息