Rahul Rana
Rahul Rana

Reputation: 103

How to hide the Viewcontroller at runtime?

How do I hide the UIViewController at runtime?

Upvotes: 2

Views: 17449

Answers (4)

meronix
meronix

Reputation: 6176

what do you really mean?

UIViewController itself is not "visible"... but it is its view (a normal UIView), so just change it's view hidden propery to YES:

yourUIViewController.view.hidden = YES;

Upvotes: 6

Madan gupta
Madan gupta

Reputation: 668

code to hide current uiviewcontroller

[self dismissViewControllerAnimated:YES completion:nil];

Upvotes: 1

oberthelot
oberthelot

Reputation: 1310

Use Animations, from your Controller (I presume you have a class implementing the UIViewController protocol).

In your UIViewController Class declare a method that do something like this :

- (void) hide
{
    [UIView animateWithDuration:0.2 //begin animation
                          delay:0.1
                        options:UIViewAnimationCurveEaseIn 
                     animations:^
                     {
                     // This subview is initialized at the top of the screen 
                     [mySubview setFrame:CGRectOffset([mySubview frame], 0, -mySubview.frame.size.height)];
                     // Do the same for Every other subview you want to animate off
                     } 
                     completion:nil];
}

That will animate your views out of the screen. It will give you a better (smooth) effect than simply making them 'hidden'.

From your superview, you just call your controller hide method and everything will smoothly go away !

Note : You can also use other animation curves...A list and description can be found here under "UIViewAnimationCurve"

Upvotes: 3

visakh7
visakh7

Reputation: 26390

If u want to hide the viewcontroller's view try

viewController.view.hidden = YES;

Upvotes: 3

Related Questions