xcode 如何呈现半屏模态视图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6907662/
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
How To Present Half Screen Modal View?
提问by Jon
I have a UIViewController and when a button is pressed, I want a half screen view to slide up with a UIPicker in it.
我有一个 UIViewController,当按下一个按钮时,我想要一个半屏视图向上滑动,其中包含一个 UIPicker。
I made a UIView in IB with the UIPicker along with a UIToolBar with Done/Cancel buttons.
我在 IB 中使用 UIPicker 以及带有完成/取消按钮的 UIToolBar 制作了一个 UIView。
How can I make it so that just this half view slides up and the background view is still showing but dimmed or cant be played with.
我怎样才能做到让这个半视图向上滑动并且背景视图仍然显示但变暗或无法播放。
I'm using this code so far:
到目前为止,我正在使用此代码:
- (void)showModalView
{
[self.popupView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.popupView];
[UIView animateWithDuration:.2 animations:^{
[self.popupView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}];
}
Here is a pic: http://www.box.net/shared/static/08ji4s0f6i1b8qubrtz6.png
这是一张图片:http: //www.box.net/shared/static/08ji4s0f6i1b8qubrtz6.png
采纳答案by Hadi
Here is what u need its an open source code on github TDSemiModalViewhaving a half view date picker. Check the demo project inside the code. Here is the link.. Hope it solves your problem.
这是你需要的 githubTDSemiModalView上的开源代码,它有一个半视图日期选择器。检查代码中的演示项目。这是链接.. 希望它能解决您的问题。
回答by Parth Bhatt
@Jon:
@乔恩:
METHOD-1:
方法一:
Make your main view transperant by setting its alpha value to 0 and add a subview to the main view which is only half of the main screen and keep it opaque (alpha value as 1) as it would be by default.
通过将主视图的 alpha 值设置为 0 来使您的主视图透明,并向主视图添加一个子视图,该子视图仅是主屏幕的一半,并保持其不透明(alpha 值为 1),就像默认情况下一样。
Then simply present the view controller using present Modal View Controller.
然后使用present Modal View Controller简单地呈现视图控制器。
Keep in mind that because of the transperancy you would be able to see half of the previous view, but wont be able to touch it as there is a transperant view.
请记住,由于透明,您将能够看到前一个视图的一半,但无法触摸它,因为有透明视图。
METHOD-2:
方法2:
Another work around is to animate a UIView which is of size half of the existing view.
另一种解决方法是为大小为现有视图一半的 UIView 设置动画。
Then you have to simply follow animation of the UIView.
然后你必须简单地遵循 UIView 的动画。
Here as it is just a UIView that will be added as subview to existing view, you will be able to touch the rest of the screen.
由于它只是一个 UIView,它将作为子视图添加到现有视图中,因此您将能够触摸屏幕的其余部分。
So you can follow either of the methods as per your requirement.
因此,您可以根据您的要求遵循其中任何一种方法。
Hope this helps you.
希望这对你有帮助。

