6

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.

Darren Findlay
  • 2,533
  • 2
  • 29
  • 46

3 Answers3

8

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"];
Daniel G. Wilson
  • 14,955
  • 2
  • 32
  • 39
5

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.

Community
  • 1
  • 1
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
0

You really don't want to try to do this using a UIViewController. Add a UIView to the current controller's view, give that view it's own non-UIViewController controller object if it needs one to manage its behavior.

I covered some of the details on how what you are trying to do is outside the contract provided by UIViewController here: http://blog.carbonfive.com/2011/03/09/abusing-uiviewcontrollers/

Jonah
  • 17,918
  • 1
  • 43
  • 70