我有一個UIViewController
,我編輯使用IB。我在上面放了一個UINavigationBar
和一個UISegmentedControl
,在他們的下面放了一個UIViews
。我希望能夠使用動畫在UIViews
之間切換,但我只想動畫UIViews
,我希望navigationBar和athe segmentedControl不移動。我顯示代碼現在我怎麼做。iOS UIView過渡,不要更改導航欄
任何想法如何我只能移動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];
}
}