0

像这样延迟加载多个视图控制器

-(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];
 }

要求是添加一个容器视图并在容器视图中加载所有视图控制器。

所以,在加载视图中可以像这样创建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;}

像这样在容器视图中加载所有视图控制器是可以的,或者在这里做错事。

感谢您对此的帮助。

谢谢。

4

1 回答 1

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 .......................
于 2012-06-28T20:24:53.280 回答