如何呈现半屏模态视图?

发布于 2024-11-27 13:29:27 字数 761 浏览 2 评论 0原文

我有一个 UIViewController,当按下按钮时,我想要一个半屏视图向上滑动,其中有一个 UIPicker。

我在 IB 中使用 UIPicker 和带有“完成/取消”按钮的 UIToolBar 制作了一个 UIView。

我怎样才能做到这一点,只有这个半视图向上滑动,背景视图仍然显示,但变暗或无法播放。

到目前为止我正在使用这段代码:

- (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)];
    }];
}

这是一张图片: http://www.box .net/shared/static/08ji4s0f6i1b8qubrtz6.png

I have a UIViewController and when a button is pressed, I want a half screen view to slide up with a UIPicker in it.

I made a UIView in IB with the UIPicker along with a UIToolBar with Done/Cancel buttons.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

并安 2024-12-04 13:29:27

@Jon:

METHOD-1:

通过将其 alpha 值设置为 0 并将子视图添加到仅占主屏幕一半的主视图并保持其不透明(alpha 值为1) 与默认情况一样。

然后简单地使用当前的模态视图控制器来呈现视图控制器。

请记住,由于透明,您将能够看到前一个视图的一半,但无法触摸它,因为存在透明视图。

方法-2:

另一种解决方法是对大小为现有视图一半的 UIView 进行动画处理。

然后你必须简单地遵循 UIView 的动画。

这里,由于它只是一个 UIView,将作为子视图添加到现有视图中,因此您将能够触摸屏幕的其余部分。

因此,您可以根据您的要求采用其中一种方法。

希望这对您有帮助。

@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.

Then simply present the view controller using 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:

Another work around is to animate a UIView which is of size half of the existing view.

Then you have to simply follow animation of the 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.

So you can follow either of the methods as per your requirement.

Hope this helps you.

呆橘 2024-12-04 13:29:27

这是您需要的 github TDSemiModalView 上的开源代码,具有半视图日期选择器。检查代码中的演示项目。这是链接..希望它能解决您的问题。

TDSemiModalClass

Here is what u need its an open source code on github TDSemiModalView having a half view date picker. Check the demo project inside the code. Here is the link.. Hope it solves your problem.

TDSemiModalClass

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文