没有导航控制器堆栈的视图控制器从一个到另一个的动画转换

Posted

技术标签:

【中文标题】没有导航控制器堆栈的视图控制器从一个到另一个的动画转换【英文标题】:Animate transition of view controllers from one to another without navigation controller stack 【发布时间】:2012-02-10 22:21:57 【问题描述】:

如何在没有导航控制器堆栈的情况下动画视图控制器从一个到另一个的过渡。 View Controller 仅由 UIToolbar 管理,因为它只有播放、倒带、停止、信息和选项按钮。我的代码现在在下面给出,我有 23 个视图控制器,它们一个接一个地加载,但在转换期间 UIToolbar 也与视图控制器一起翻转,这是错误的。

-(void)playAction:(id)sender

[audioPlayer play];
[self performSelector:@selector(displayviewsAction:) withObject:nil afterDelay:11.0];


- (void)displayviewsAction:(id)sender
 
First *firstController = [[First alloc] init];
firstController.view.frame = CGRectMake(0, 0, 320, 480);
CATransition *transitionAnimation = [CATransition animation]; 
[transitionAnimation setDuration:1];  
[transitionAnimation setType:kCATransitionFade];   
[transitionAnimation setTimingFunction:[CAMediaTimingFunction     functionWithName:kCAMediaTimingFunctionEaseIn]];  
[self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];
[self.view addSubview:firstController.view];
[self.view addSubview:toolbar];
[firstController release];  
self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];    


-(void)Second

Second *secondController = [[Second alloc] init];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
CATransition *transitionAnimation = [CATransition animation];
[transitionAnimation setDuration:1];
[transitionAnimation setType:kCATransitionFade];
[transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];
[self.view addSubview:secondController.view];
[self.view addSubview:toolbar];
[secondController release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(Third) userInfo:nil repeats:NO];


-(void)Third 
Third *thirdController = [[Third alloc] init];
thirdController.view.frame = CGRectMake(0, 0, 320, 480);
CATransition *transitionAnimation = [CATransition animation];
[transitionAnimation setDuration:1];
[transitionAnimation setType:kCATransitionFade];
[transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];   
[self.view addSubview:thirdController.view];
[self.view addSubview:toolbar];
[thirdController release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Fourth) userInfo:nil repeats:NO];


-(void)Fourth 
Fourth *fourthController = [[Fourth alloc] init];
fourthController.view.frame = CGRectMake(0, 0, 320, 480);
CATransition *transitionAnimation = [CATransition animation];
[transitionAnimation setDuration:1];
[transitionAnimation setType:kCATransitionReveal];
[transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[self.view.layer addAnimation:transitionAnimation forKey:kCATransitionReveal];
[self.view addSubview:fourthController.view];
[self.view addSubview:toolbar];
[fourthController release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:25 target:self selector:@selector(Fifth) userInfo:nil repeats:NO];

我仍在寻找解决方案。将不胜感激。

【问题讨论】:

不太确定你在问什么。 UIViews 作为子视图添加,而不是 UIViewControllers。在上面的示例中,您自动释放 viewController,但将其视图添加为子视图。这个新视图的控制器现在将消失,并可能导致错误。你到底想做什么? 在主视图控制器上有一个 UIToolbar 和播放按钮,当按下该按钮时,它会播放音频文件并一个接一个地显示多个 uiview。到目前为止,我能够实现该按钮播放音频文件并显示视图现在我想添加更多视图以一个接一个地显示 【参考方案1】:

把它们全部推倒

NSMutableArray *controllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];
[controllers addObject:vc1];
[controllers addObject:vc2];
[controllers addObject:vc3];
[controllers addObject:vc4];
[self.navigationController setViewControllers:controllers animated:YES];

【讨论】:

以上是关于没有导航控制器堆栈的视图控制器从一个到另一个的动画转换的主要内容,如果未能解决你的问题,请参考以下文章

从导航堆栈中弹出视图控制器时从右侧滑入

弹出到根视图控制器,没有表视图的动画崩溃

使用情节提要逆转自定义 Segue

滑动单元格时,有没有办法从 tableViewCell 导航到另一个视图控制器?

有没有办法找出视图控制器是不是从导航堆栈中弹出?

如何从堆栈中弹出视图控制器而不导航到它们