0

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;
}
Tapy
  • 1,044
  • 6
  • 17
  • 30
  • possible duplicate of [Open view with slide effect from bottom to top on iPhone](http://stackoverflow.com/questions/1312366/open-view-with-slide-effect-from-bottom-to-top-on-iphone) – Nikita Rybak Apr 25 '11 at 10:53
  • yes me also +1 for duplicate, your link answers exactly this question – Tomasz Stanczak Apr 25 '11 at 11:01

2 Answers2

4

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);
                     }];
}
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
  • The problem is that it goes "under" the first view so all buttons etc from the first view is still displayed in the view that animated up. How would I fix that? – Tapy Apr 25 '11 at 16:36
  • By calling `[self.view bringSubviewToFront:loginView];`, added it to the solution as well. – Nick Weaver Apr 25 '11 at 19:06
1

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!

Fran Sevillano
  • 8,103
  • 4
  • 31
  • 45