I'm working on an app where 1 ViewController has a UISegmentControl with these behaviours:
Segment 1 (if it's not already in position):
- Fade in items
- Slide segment control down
Segment 2 (if it's not already in position):
- Fade out items
- Slide segment control up
Segment 3 (if it's not already in position):
- Not implemented yet, but similar to Segment 2
To achieve this, I'm using this code:
- (IBAction)segmentControlAction:(id)sender {
// Change which container will be visible
int selectedIndex = self.overviewSegmentControl.selectedSegmentIndex;
if (selectedIndex == 0) {
// Show details and hide reviews & related
self.detailContainer.hidden = NO;
self.relatedContainer.hidden = YES;
// SHOW THE DETAILS
[self showDetails];
} else if (selectedIndex == 1) {
// Show Reviews and hide details & related
self.reviewsContainer.hidden = NO;
self.relatedContainer.hidden = YES;
// SHOW THE REVIEWS
[self showOther];
} else if (selectedIndex == 2) {
// Show related and hide details & reviews
self.relatedContainer.hidden = NO;
self.reviewsContainer.hidden = YES;
}
}
-(void)showOther {
// Animate the reviews
[UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:.9 initialSpringVelocity:1 options:UIViewAnimationOptionTransitionNone animations:^{
// Hide details controls
self.profileImageView.alpha = 0;
self.seperatorImageView.alpha = 0;
self.byLabel.alpha = 0;
self.authorLabel.alpha = 0;
// Move segmentControl
[self.overviewSegmentControl setFrame:CGRectMake(self.overviewSegmentControl.frame.origin.x, self.previewImageView.frame.size.height + 8, self.overviewSegmentControl.frame.size.width, self.overviewSegmentControl.frame.size.height)];
}completion:^(BOOL finished) {
// Completed
}];
}
-(void)showDetails{
// Animate the details
[UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:.9 initialSpringVelocity:1 options:UIViewAnimationOptionTransitionNone animations:^{
// Move segmentControl
[self.overviewSegmentControl setFrame:CGRectMake(self.overviewSegmentControl.frame.origin.x, self.previewImageView.frame.size.height + 85, self.overviewSegmentControl.frame.size.width, self.overviewSegmentControl.frame.size.height)];
// Hide details controls
self.profileImageView.alpha = 1;
self.seperatorImageView.alpha = 1;
self.byLabel.alpha = 1;
self.authorLabel.alpha = 1;
}completion:^(BOOL finished) {
// Completed
}];
}
The 2nd segment works perfect - where a few controls are fade out and the segment control slides up. However, 1st segment makes the segment snap back down and rapidly visualise the other controls instead of doing the same nice animation that happens with segment 1.
Any ideas why this happens and how I can fix it?
EDIT:
ViewController:
The controls below the big UIImageView are supposed to fade away while the segment control slides up right below the main UIImageView. The opposite when the -(void)showDetails method is called.
Thanks! Erik