NOTE. This solution is broken in iOS 8. I will publish a new solution as soon as possible.
I am going to answer here using a storyboard, but this is also possible without a storyboard.
Init: Create two UIViewController in the storyboard.
- lets say
FirstViewController , which is normal, and SecondViewController , which will pop up.
Modal Segue: Place the UIButton in the FirstViewController and create a segue on this UIButton before the SecondViewController as a modal segment.
Make it transparent: Now select the UIView (the default UIViewController with the UIViewController ) SecondViewController and change its background color to clear the color.
Make a background image Dim: Add a UIImageView to the SecondViewController , which covers the entire screen and sets its image to some kind of semi-dark translucent image. You can get a sample from here: UIAlertView Background Image
Display Design: Now add a UIView and create any design you want to show. Here is a screenshot of my storyboard 
- Here I add a segue to the login button that opens the
SecondViewController as a popup to ask for a username and password
Important: Now this is the main step. We want SecondViewController not to completely hide FirstViewController. We set a clear color, but thatβs not enough. By default, it adds black for the presentation of the model, so we need to add one line of code to the viewDidLoad FirstViewController . You can add it to another place, but it should work before the start.
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
Reject:. When the deviation depends on your use case. This is a modal presentation, therefore, to reject, we do what we do for a modal presentation:
[self dismissViewControllerAnimated:YES completion:Nil];
That's all.....
Any suggestions or comments are welcome.
Demo: You can get a demo project project from here: Pop-up demo
NEW Someone has done a very good job on this concept: MZFormSheetController
New one . I found another code to get such a function: KLCPopup
IOS 8 update . I used this method to work with both iOS 7 and iOS 8
+ (void)setPresentationStyleForSelfController:(UIViewController *)selfController presentingController:(UIViewController *)presentingController { if (iOSVersion >= 8.0) { presentingController.providesPresentationContextTransitionStyle = YES; presentingController.definesPresentationContext = YES; [presentingController setModalPresentationStyle:UIModalPresentationOverCurrentContext]; } else { [selfController setModalPresentationStyle:UIModalPresentationCurrentContext]; [selfController.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext]; } }
You can use this method inside prepareForSegue, how to do it
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { PopUpViewController *popup = segue.destinationViewController; [self setPresentationStyleForSelfController:self presentingController:popup] }
CRDave Apr 26 '13 at 7:13 2013-04-26 07:13
source share