2

I would like to create a UIVewController and have it popup similar to what is shown in this image: https://i.stack.imgur.com/WzMKk.png

When the user taps outside the popup window, the window (view controller) goes away. Can someone please provide some example code as far as what goes in the .h files, and .m file, and any extra steps I may need to follow in the interface builder?

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
rs14smith
  • 589
  • 2
  • 6
  • 8

2 Answers2

2

Use UIPopoverController - http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPopoverController_class/Reference/Reference.html#//apple_ref/occ/cl/UIPopoverController

Bartek
  • 1,986
  • 1
  • 14
  • 21
  • From every tutorial I've viewed regarding the UIPopoverController does not appear to be what is shown in the image I provided. In the image, they do not have an arrow pointing at a certain object, it's just a popup view/viewcontroller. Are you sure this is what they are using as shown in the image? – rs14smith Sep 30 '11 at 08:26
  • 1
    Use this to display popover without arrow (arrow direction 0 means no arrow) `[self.popoverController presentPopoverFromBarButtonItem:anItem permittedArrowDirections:0 animated:YES];` – Bartek Sep 30 '11 at 08:50
0

It's just a UIViewController presented modally with the popup's view controller modalPresentationStyle set to UIModalPresentationFormSheet.

MyPopupViewController *popup = ...
popup.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:popup animated:YES];

From the docs regarding UIModalPresentationFormSheet presentation style...

The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.

You'll need to detect touches on the darkened area to allow the form to be dismissed that way. This answer has some details on implemented that.

Community
  • 1
  • 1
Jason Harwig
  • 43,743
  • 5
  • 43
  • 44