开发者

How To Present Half Screen Modal View?

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
{
 开发者_JS百科   [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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜