Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present a view Controller that is half the size of the screen

Tags:

xcode

ios

iphone

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.

like image 646
Darren Findlay Avatar asked Apr 27 '11 14:04

Darren Findlay


2 Answers

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.

Place the half sized view below the screen (halfView.y = 480 or 320 depending on orientation).

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"];
like image 86
Daniel G. Wilson Avatar answered Oct 22 '22 18:10

Daniel G. Wilson


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.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

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.

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.

like image 29
LuckyLuke Avatar answered Oct 22 '22 18:10

LuckyLuke