Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>NOTE : This solution is broken in iOS 8. I will post new solution ASAP.</strong></p> <p>I am going to answer here using storyboard but it is also possible without storyboard.</p> <ol> <li><p><strong>Init:</strong> Create two <code>UIViewController</code> in storyboard.</p> <ul> <li>lets say <code>FirstViewController</code> which is normal and <code>SecondViewController</code> which will be the popup. <p></li> </ul></li> <li><p><strong>Modal Segue:</strong> Put <code>UIButton</code> in FirstViewController and create a segue on this <code>UIButton</code> to <code>SecondViewController</code> as modal segue.</p></li> <li><p><strong>Make Transparent:</strong> Now select <code>UIView</code> (<code>UIView</code> Which is created by default with <code>UIViewController</code>) of <code>SecondViewController</code> and change its background color to clear color.</p></li> <li><p><strong>Make background Dim:</strong> Add an <code>UIImageView</code> in <code>SecondViewController</code> which covers whole screen and sets its image to some dimmed semi transparent image. You can get a sample from here : <a href="http://lh5.ggpht.com/_QLwms0mVa4w/S_FsI-DMghI/AAAAAAAAAp8/-4Uwv-yDhVY/behind_alert_view.png?imgmax=800"><code>UIAlertView</code> Background Image</a></p></li> <li><p><strong>Display Design:</strong> Now add an <code>UIView</code> and make any kind of design you want to show. Here is a screenshot of my storyboard <img src="https://i.stack.imgur.com/RLRef.png" alt="storyboard"></p> <ul> <li>Here I have add segue on login button which open <code>SecondViewController</code> as popup to ask username and password</li> </ul></li> <li><p><strong>Important:</strong> Now that main step. We want that <code>SecondViewController</code> doesn't hide FirstViewController completely. We have set clear color but this is not enough. By default it adds black behind model presentation so we have to add one line of code in viewDidLoad of <code>FirstViewController</code>. You can add it at another place also but it should run before segue.</p> <p><code>[self setModalPresentationStyle:UIModalPresentationCurrentContext];</code></p></li> <li><p><strong>Dismiss:</strong> When to dismiss depends on your use case. This is a modal presentation so to dismiss we do what we do for modal presentation:</p> <p><code>[self dismissViewControllerAnimated:YES completion:Nil];</code></p></li> </ol> <p>Thats all.....</p> <p>Any kind of suggestion and comment are welcome.</p> <p><strong>Demo :</strong> You can get demo source project from Here : <a href="https://github.com/chinatndave/popupDemo">Popup Demo</a></p> <p><strong>NEW</strong> : Someone have done very nice job on this concept : <a href="https://github.com/m1entus/MZFormSheetController">MZFormSheetController</a><BR> <strong>New</strong> : I found one more code to get this kind of function : <a href="https://github.com/jmascia/KLCPopup">KLCPopup</a></p> <hr> <blockquote> <p><strong>iOS 8 Update</strong> : I made this method to work with both iOS 7 and iOS 8 <BR></p> </blockquote> <pre><code>+ (void)setPresentationStyleForSelfController:(UIViewController *)selfController presentingController:(UIViewController *)presentingController { if (iOSVersion &gt;= 8.0) { presentingController.providesPresentationContextTransitionStyle = YES; presentingController.definesPresentationContext = YES; [presentingController setModalPresentationStyle:UIModalPresentationOverCurrentContext]; } else { [selfController setModalPresentationStyle:UIModalPresentationCurrentContext]; [selfController.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext]; } } </code></pre> <hr> <p>Can use this method inside prepareForSegue deligate like this</p> <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { PopUpViewController *popup = segue.destinationViewController; [self setPresentationStyleForSelfController:self presentingController:popup] } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload