Tapy
Tapy

Reputation: 1054

Objective-c Hidden View animation

Hello I have a hidden view inside of my view that appears by the click of a button. But when you click on the button I want the view to do an slide up animation so it won't just appear but slide up to it's position.

Here is the code for my hidden view: in .h:

@interface hidden_viewsViewController : UIViewController {

    IBOutlet UIView *loginview;

}

@property (nonatomic, retain) IBOutlet UIView *loginview;

- (IBAction)login;
- (IBAction)logout;

And in .m

@synthesize loginview;

- (IBAction)login {

    loginview.hidden = NO;

}

- (IBAction)logout {

    loginview.hidden = YES;

}

- (void)viewDidLoad {
    [super viewDidLoad];

    loginview.hidden = YES;
}

Upvotes: 0

Views: 10352

Answers (2)

Nick Weaver
Nick Weaver

Reputation: 47241

Try, assuming the view is in portrait orientation:

- (IBAction)login {
    [self.view bringSubviewToFront:loginView];
    loginview.frame = CGRectMake(0, 480, 320, 480); 
    loginview.hidden = NO;
    [UIView animateWithDuration:1.0 
                     animations:^{
                         loginview.frame = CGRectMake(0, 0, 320, 480);
                     }];
}

Upvotes: 4

Fran Sevillano
Fran Sevillano

Reputation: 8163

you should change the frame property of your view, and you should do it within an animations block, as follows:

-(IBAction)login
{
    [UIView beginAnimations:@"showView" context:nil];
    [UIView setAnimationDuration:0.5];
    CGRect viewNewFrame = self.view.frame;
    viewNewFrame.origin.y = 0;
    self.view.frame = viewNewFrame;
    [UIView commitAnimations];
 }

Hope it helps!

Upvotes: 1

Related Questions