2012-06-28 45 views
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]; 
} 

要求是增加一個容器視圖和加載所有視圖控制器在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

首先除去的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 ....................... 
+0

I M尋找如何在容器視圖加載。 – user1452248

相關問題