How can I present a UIView from the bottom of the screen like a UIActionSheet? How can I present a UIView from the bottom of the screen like a UIActionSheet? objective-c objective-c

How can I present a UIView from the bottom of the screen like a UIActionSheet?


Do what Matt did here, but just change the values and direction. I have code at home to do this from the bottom if you need it later (I'll update this post).

Link: http://cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html

Also, don't forget to take out the bit of code that shifts the main view downward (so instead the UIView just pops over top like an ActionSheet)

Updated with code:

This is what I use in one of my apps to show/hide a little "options" view:

- (void)toggleOptions:(BOOL)ViewHidden{// this method opens/closes the player options view (which sets repeat interval, repeat & delay on/off)if (ViewHidden == NO){    // delay and move view out of superview    CGRect optionsFrame = optionsController.view.frame;    [UIView beginAnimations:nil context:nil];    optionsFrame.origin.y += optionsFrame.size.height;    optionsController.view.frame = optionsFrame;    [UIView commitAnimations];    [optionsController.view     performSelector:@selector(removeFromSuperview)     withObject:nil     afterDelay:0.5];    [optionsController     performSelector:@selector(release)     withObject:nil     afterDelay:0.5];    optionsController = nil;}else{    optionsController = [[PlayOptionsViewController alloc] init];    //    // Position the options at bottom of screen    //    CGRect optionsFrame = optionsController.view.frame;    optionsFrame.origin.x = 0;    optionsFrame.size.width = 320;    optionsFrame.origin.y = 423;    //    // For the animation, move the view up by its own height.    //    optionsFrame.origin.y += optionsFrame.size.height;    optionsController.view.frame = optionsFrame;    [window addSubview:optionsController.view];    [UIView beginAnimations:nil context:nil];    optionsFrame.origin.y -= optionsFrame.size.height;    optionsController.view.frame = optionsFrame;    [UIView commitAnimations];}}


One way would be to use the present modal view controller on the view controller:

presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated

For more info take a look at the UIViewController documentation.

EDIT: If you want a mid-screen view you'll need to animate it into position as @jtbandes has pointed out. I suggest also adding some candy to UIView animation block:

[UIView beginAnimations:nil context:nil];[UIView setAnimationDuration:0.4];[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];myView.center = CGPointMake(x,y);[UIView commitAnimations];

You can then move it again if you need to go full screen or dismiss it.


You'll have to move the view yourself, by setting its center or frame. I'll let you figure out what to set those to. But for the animation:

// set the view to its initial position here...[UIView beginAnimations:nil context:NULL];// move the view into place here...[UIView commitAnimations];