tags:

views:

49

answers:

2

How can I make a custom view in iOS which appears above the existing view,but smaller? It should be like UIAlertView, but taken from a .xib file. After user taps a certain button, the small view vanishes and the normal view appears.

If this is posiible, how can I do it? And.. if it's not hard for you, please, include code.

Thanks in advance!

A: 

You can just use the addSubview: method on your UIWindow or your visible UIViewController's view to show the UIView, and you can hide/remove it later by calling removeFromSuperview on the presented UIView.

Douwe Maan
How should I do it? Should I create a separate .nib? And what's the code I shall write? I'm writing AppViewController *subView = [[AppViewController alloc] initWithNibName:@"SubVIEW" bundle:nil]; [self.view insertSubview:subView.view atIndex:0]; where SubVIEW is a separate .xib.
Knodel
A: 

I think what you're looking for is a modal view. Modal views make it easy to have a view take over the screen for a little while, then when they get dismissed have the background view resume where it left off without having to worry about who's on top or handling events in partially-obscured views.

Here is Apple's article describing it.

They key is to have the controller class for your view call [self presentModalViewController:popupController animated:YES]; where "popupController" is the view controller for the view you want to show up. When you're ready to make it go away, call [self dismissModalViewControllerAnimated: YES];

samkass