xcode 呈现一个屏幕一半大小的视图控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5805816/
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
Present a view Controller that is half the size of the screen
提问by Darren Findlay
I'm trying to present a view controller thats only half the height using
我正在尝试展示一个只有一半高度的视图控制器
[self presentModalViewController:menu animated:YES];
The problem is when it's presented, the view controller ends the same size as the screen. I've also tried making the 'menu' the full size of the screen and changing the view's transparency to white but that doesn't work either.
问题是当它出现时,视图控制器结束时与屏幕大小相同。我还尝试将“菜单”设为屏幕的全尺寸并将视图的透明度更改为白色,但这也不起作用。
回答by Daniel G. Wilson
Just use core animation or animation transitions with a UIView that is half the size of the screen. You'll need a holder view that you add to the main view.
只需将核心动画或动画过渡与屏幕大小一半的 UIView 一起使用即可。您将需要添加到主视图的持有人视图。
Place the half sized view below the screen (halfView.y = 480 or 320 depending on orientation).
将一半大小的视图放置在屏幕下方(halfView.y = 480 或 320,具体取决于方向)。
Animate it upwards.
向上动画。
Something like this maybe:
可能是这样的:
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[holderView addAnimation:animation forKey:@"SwitchToView1"];
回答by LuckyLuke
On iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.
在 iPhone 和 iPod touch 设备上,modalViewController 的视图总是全屏显示。在 iPad 上,演示文稿取决于 modalPresentationStyle 属性中的值。
If you want to only cover some part of the screen you can make an animation that slides a UIView container and whatever you want to show to a position on the screen.
如果您只想覆盖屏幕的某些部分,您可以制作一个滑动 UIView 容器的动画,以及您想在屏幕上的某个位置显示的任何内容。
I would recommend you to read this post: Transparent Modal View on Navigation Controller
我建议您阅读这篇文章:导航控制器上的透明模态视图
"I tried to make the view background white"
“我试图将视图背景设为白色”
That would definitley not work, you could have written [UIColor clearColor]
however, the view controller's view which is covered by the modal one will disappear from the screen when the animation is done. So if you make the background white you probably end up watching the windows background instead, which is white and is not what you want.
那肯定是行不通的,你可以写[UIColor clearColor]
但是,当动画完成时,被模态视图覆盖的视图控制器的视图将从屏幕上消失。因此,如果您将背景设为白色,您可能最终会改为观看 Windows 背景,它是白色的并且不是您想要的。
回答by Jonah
You really don't want to try to do this using a UIViewController. Add a UIView to the current controller's view, give that view it's own non-UIViewController controller object if it needs one to manage its behavior.
你真的不想尝试使用 UIViewController 来做到这一点。将 UIView 添加到当前控制器的视图中,如果它需要一个来管理其行为,则为该视图提供它自己的非 UIViewController 控制器对象。
I covered some of the details on how what you are trying to do is outside the contract provided by UIViewController here: http://blog.carbonfive.com/2011/03/09/abusing-uiviewcontrollers/
我在 UIViewController 提供的合同之外介绍了一些有关您尝试执行的操作的详细信息:http: //blog.carbonfive.com/2011/03/09/abusing-uiviewcontrollers/