my bad! i thought withDuration
was in ms. It's in seconds!
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
bg1 = [[UIView alloc] initWithFrame:self.view.frame];
[bg1 setBackgroundColor:[UIColor redColor]];
bg2 = [[UIView alloc] initWithFrame:self.view.frame];
[bg2 setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:bg1];
[self.view addSubview:bg2];
[self.view bringSubviewToFront:bg1];
[self animate];
}
- (void)animate {
[UIView animateWithDuration:3 animations:^{
bg1.frame = CGRectOffset(bg1.frame, 0, bg1.frame.size.height);
}completion:^(BOOL done) {
if (done) {
bg1.frame = CGRectOffset(bg1.frame, 0, -bg1.frame.size.height);
[self.view sendSubviewToBack:bg1];
[UIView animateWithDuration:3 animations:^{
bg2.frame = CGRectOffset(bg2.frame, 0, bg2.frame.size.height);
}completion:^(BOOL done) {
if (done) {
bg2.frame = CGRectOffset(bg2.frame, 0, -bg2.frame.size.height);
[self.view sendSubviewToBack:bg2];
[self animate];
}
}];
}
}];
}