有一个主视图控制器,它作为 uiimageview 和 uitoolbar,当按下 uitoolbar 上的按钮时,它会根据 nstimer 一个接一个地加载多个视图控制器。我想让这个 mainviewcontroller 作为容器一个接一个地加载多个视图控制器,基于 nstimer 和 uitoolbar 总是显示在下面。不想在每个视图控制器中添加工具栏作为子视图。我怎样才能做到这一点。
- (void)viewDidLoad{
// Displays UIImageView
UIImageView *myImage = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"ka1_046.png"]];
myImage.frame = CGRectMake(0, 0, 320, 460);
[self.view addSubview:myImage];
// create the UIToolbar at the bottom of the view controller
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 425, 320, 40)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[self.view addSubview:toolbar];
//Add Play Button
self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.playButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
self.playButton.frame = CGRectMake(0, 0, 30, 30);
[self.playButton setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateNormal];
[self.playButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithCustomView:self.playButton];
-(void)playpauseAction:(id)sender {
if([audioPlayer isPlaying])
{
[sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[self pauseTimer];
[self pauseLayer:self.view.layer];
}else{
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self resumeTimer];
[self resumeLayer:self.view.layer];
if(isFirstTime == YES)
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
isFirstTime = NO;
}} }
- (void)displayviewsAction:(id)sender{
First *first = [[First alloc] init];
first.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:first.view];
[self.view addSubview:toolbar];
[first release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];
}
以同样的方式,基于 nstimer 一个接一个地加载其他多个视图控制器。那么我怎样才能让这个mainviewcontroller作为容器来加载这些多个视图控制器一个接一个地基于nstimer并且总是在下面有uitoolbar。
感谢帮助。