一个接一个地加载多个视图控制器,像这样延迟
-(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 *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:kCATransitionReveal];
[transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[self.view.layer addAnimation:transitionAnimation forKey:kCATransitionReveal];
[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];
}
要求是添加容器视图并加载containerview中的所有视图控制器。
因此,在加载视图中可以像这样创建uiview和容器视图
- (void)loadView
{
// set up the base view
CGRect frame = [[UIScreen mainScreen] applicationFrame];
UIView *view = [[UIView alloc] initWithFrame:frame];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view.backgroundColor = [UIColor blueColor];
// set up content view a bit inset
frame = CGRectInset(view.bounds, 0, 100);
_containerView = [[UIView alloc] initWithFrame:frame];
_containerView.backgroundColor = [UIColor redColor];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[view addSubview:_containerView];}
在AppDelegate中可以这样做
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ContainerViewController *container = [[ContainerViewController alloc] init];
self.window.rootViewController = container;
// make an array of 23 PageVCs
NSMutableArray *controllers = [NSMutableArray array];
[controllers addObject:firstcontroller];
[controllers addObject:secondcontroller];
[controllers addObject:.....];
[controllers addObject:twentythreecontroller];
for (int i=0; i<23; i++)
{
First *firstController = [[First alloc] init];
[controllers addObject:firstcontroller, secondcontroller, .....,twentythreecontroller];
}
// set these as sub VCs
[container setSubViewControllers:controllers];
[self.window makeKeyAndVisible];
return YES;}
在容器视图中加载所有viewcontrollers就可以了,或者在这里做错了。
为此提供帮助。
感谢。
答案 0 :(得分:0)
首先删除 nstimer 并使用 performSelector:withObject:afterDelay:方法,如下所示:
// add delay and method according to your requirement
[self performSelector:@selector(oneView) withObject:nil afterDelay:10];
-(void)oneView
{
//add firstView and perform second selector
[self performSelector:@selector(secondView) withObject:nil afterDelay:10];
}
-(void)secondView
{
//add secondView and perform thirdselector
[self performSelector:@selector(thirdView) withObject:nil afterDelay:10];
}
goes on .......................