Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: How To Create A PopUp View Controller That Appears In Another View Controller

Basically what I am trying to figure out to do is, say I have one View Controller, called V1, that has a regular view inside it and a button. Now, when you tap that button, I want that button to create an action that pop-ups another View Controller, called V2, within the same view controller, V1.

V2 will be reduced in size some so that it does not fill the entire screen, but you can still see the first layer which is V1 behind V2. So basically, you never really leave V1. I hope this makes sense for what I'm trying to do. I know the MTV app has this functionity. An image of what I'm talking about is here: https://docs.google.com/leaf?id=0BzlCAVXRsIPcNWUxODM2MDAtNDE3OS00ZTc4LTk5N2MtZDA3NjFlM2IzNmZk&hl=en_US

Sample code or an example is what I'm looking for as well.

Thanks

like image 765
rs14smith Avatar asked Sep 14 '11 04:09

rs14smith


People also ask

How do I present a view controller from another view controller?

Start a segue from any object that implements an action method, such as a control or gesture recognizer. You may also start segues from table rows and collection view cells. Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present.


1 Answers

If you're using Storyboard, you can follow this step:

  1. Add a view controller (V2), setup the UI the way you want it

*based on the image you attached

  • add an UIView - set background to black and opacity to 0.5
  • add an UIImageView - that will serve as your popup (Pls take note that the image and the view must not have the same level/hierarchy. Dont make the imageview the child of the view otherwise the opacity of the uiview will affect the uiImageView)
  1. Present V2 Modally

  2. Click the segue. In the Attributes inspector, Set Presentation as Over Full Screen. Remove animation if you like

Storyboard

  1. Select V2. In the Attributes inspector, Set Presentation as Over Full Screen. Check Defines Context and Provides Context

Storyboard

  1. Select the MainView of your V2 (Pls. Check image). Set backgroundColor to Clear Color

Storyboard

like image 141
dhin Avatar answered Sep 18 '22 15:09

dhin