How To Present Half Screen Modal View?

点点圈 提交于 2019-12-07 07:22:30

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/6907662/how-to-present-half-screen-modal-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!