我有一个UIViewController
我使用 IB 编辑的。我在上面放了aUINavigationBar
和a ,在它们下面放了UISegmentedControl
3 UIViews
。我希望能够在UIViews
使用动画之间切换,但我只想制作动画UIViews
,我希望导航栏和分段控件不移动。我展示了我现在如何做的代码。
知道我如何只能移动 3 个视图吗?
- (IBAction)segmentedControlValueChanged:(id)sender {
UISegmentedControl* segmentedControl = sender;
if(lastSelectedViewIndex != [segmentedControl selectedSegmentIndex]) {
CATransition *transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
if(lastSelectedViewIndex < [segmentedControl selectedSegmentIndex])
transition.subtype = kCATransitionFromLeft;
else
transition.subtype = kCATransitionFromRight;
transition.removedOnCompletion = YES; // force removal of animation when completed.
{
switch ([segmentedControl selectedSegmentIndex]) {
case 0:
[self.usageScenarioView setHidden:NO];
[self.loginCredentialsView setHidden:YES];
[self.whatItCoversView setHidden:YES];
[self.pageControl setCurrentPage:0];
break;
case 1:
[self.usageScenarioView setHidden:YES];
[self.loginCredentialsView setHidden:NO];
[self.whatItCoversView setHidden:YES];
[self.pageControl setCurrentPage:1];
break;
case 2:
[self.usageScenarioView setHidden:YES];
[self.loginCredentialsView setHidden:YES];
[self.whatItCoversView setHidden:NO];
[self.pageControl setCurrentPage:2];
break;
}
}
lastSelectedViewIndex = [segmentedControl selectedSegmentIndex];
[self.view.layer addAnimation:transition forKey:nil];
}
}