将视图控制器从一个视图控制器移动到另一个视图控制器而无需导航控制器堆栈
问题描述:
我如何在没有导航控制器堆栈的情况下将视图控制器从一个视图转换为另一个视图控制器。 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];
}
我仍然在寻找解决方案。将感谢帮助。
答
只是把它们全部
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];
不是真的知道你是问什么。 UIViews被添加为子视图,而不是UIViewControllers。在上面的示例中,您自动释放viewController,但将其视图添加为子视图。这个新视图的控制器现在将消失,并可能导致错误。你究竟想要做什么? – picciano 2012-02-10 22:30:18
在mainviewcontroller上有一个UIToolbar和Play按钮,当它按下该按钮时,它会播放音频文件并一个接一个地显示多个uiviews。到目前为止,我可以实现这个按钮播放audiofile和显示视图,现在我想添加更多的视图来显示一个接一个 – user1120133 2012-02-10 22:33:55