tags:

views:

35

answers:

2

Okay, I am still learning how to program and things are moving along quite well, but I have a question for the group about something that has been plaguing me:

How do I create a pop view where the background can still be seen? I mean, say my iPad view has 5 buttons on it, and I want a small square to pop up over where that button was, asking the user a question - how would i do that? Can I make a modal view with an invisible background? (I don't want a UIAlert BTW - I know that would solve my problem, but I am trying to learn how to do this with my own view)

Can anyone point me in the right direction?

A: 

You should create a custom UIView with the dimensions and content that you want to display. Then, you can place the custom UIView on screen by calling something like:

//where 'self' is the view controller currently visible and 'customView' is 
//the view which has the question for the user.  Don't forget to set the 
//frame property on customView so that it knows the correct place to display.
[self.view addSubview:customView];

Hope this helps. Andrew

Andrew Little
Not sure exactly what you mean by creating a UIView. Is that something that has to be entirely coded? I tried to add a "View" to the nib of the view that I want to call this view from but it doesn't seem to work properly. Do I have to create a whole new view controller and nib for this UIView?
Rob
sorry my answer wasn't very clear. are you happy with the answer above? or, did you want to create a custom looking modal view? I was describing a way of creating a custom view that could be placed anywhere on the screen without obscuring the rest of the UI. If you're still looking for an answer, please let me know and I'll try again :-)
Andrew Little
A: 

You say "pop view" which makes me think you're describing a popover. Have you read the iPad Programming Guide, specifically, the section "Creating and Presenting a Popover"? It really is required reading in this case.

Are you showing the popover from a bar button? If so, you'll want to use presentPopoverFromBarButtonItem:permittedArrowDirections:animated:. If not, you'll need to identify a CGRect that represents the button (you can use its bounds), and then use presentPopoverFromRect:inView:permittedArrowDirections:animated:.

You do not want to obscure the button with the popover. When you show the popover using the above methods, the framework will take care of positioning the popover on-screen. Use the UIPopoverArrowDirectionAny for directions whenever possible.

If you actually want to show a modal view, you can create whatever view you want and then display it in such a way that the background is not fully obscured. Just set the modalPresentationStyle of the view controller to something like UIModalPresentationPageSheet.

Shaggy Frog