我正在开发一个应用,其中1个ViewController有一个带有这些行为的UISegmentControl:
第1段(如果它尚未就位):
第2段(如果它尚未就位):
第3段(如果它尚未就位):
为实现这一目标,我正在使用此代码:
- (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
}];
}
第二段工作完美 - 少数控件淡出,段控制向上滑动。但是,第一个段会使该段快速向下并快速显示其他控件,而不是执行与段1相同的漂亮动画。
为什么会发生这种情况以及如何解决这个问题?
修改
的ViewController:
大UIImageView下面的控件应该逐渐消失,而段控件在主UIImageView正下方滑动。调用 - (void)showDetails方法时相反。
谢谢! 埃里克