One solution is to set both button2 and button3 as a preview in another UIView and animate the presentation instead of each of the buttons separately. Whether this is a good approach depends on what you are trying to accomplish with a complex button.
EDIT:
Since my experience is that the animations inside the block are synchronized, I implemented the code as shown below. I tried numerous values ββfor the duration of the animation (0.15, 0.25, 0.75, 1.25) and button2 and Button3 move synchronously (and since button2 is on top of Button3, I cannot actually see Button3 at all until I click on button2, which makes button 3 move out from under button 3).
- (IBAction)button1Tapped:(id)sender { NSLog(@"button1Tapped..."); [UIView animateWithDuration:0.75f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) { self.button2.frame = CGRectOffset(self.button2.frame, 0.0f, 20.0f); self.button3.frame = CGRectOffset(self.button3.frame, 0.0f, 20.0f); } completion:^(BOOL finished) { NSLog(@"Finished"); }]; } - (IBAction)button2Tapped:(id)sender { NSLog(@"button2Tapped..."); [UIView animateWithDuration:0.75f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) { self.button3.frame = CGRectOffset(self.button3.frame, 0.0f, 20.0f); } completion:^(BOOL finished) { NSLog(@"Finished"); }]; } - (IBAction)button3Tapped:(id)sender { NSLog(@"button3Tapped..."); }
source share