2012-02-15 171 views
1

執行此操作時,它直接顯示secondviewcontroller,我想要的是viewcontroller首先顯示,40或50秒後顯示secondviewcontroller,等等。延遲顯示子視圖

- (void)displayviewsAction:(id)sender 
{ 
PageOneViewController *viewController = [[PageOneViewController alloc] init]; 

viewController.view.frame = CGRectMake(0, 0, 320, 480); 

SecondViewController *secondController = [[SecondViewController alloc] init]; 

secondController.view.frame = CGRectMake(0, 0, 320, 480); 

[self.view addSubview:viewController.view]; 

[self.view addSubview:secondController.view]; 

[self.view bringSubviewToFront:viewController.view]; 

[self.view addSubview:toolbar]; 

[self.view sendSubviewToBack:viewController.view]; 

[self.view addSubview:toolbar]; 

} 

任何人有任何想法,我可以做到這一點。

回答

1

可以在一個單獨的方法中添加secondViewController和呼叫使用 performSelector:withObject:afterDelay

- (void)displayviewsAction:(id)sender { 

PageOneViewController *viewController = [[PageOneViewController alloc] init];  
viewController.view.frame = CGRectMake(0, 0, 320, 480); 
[self.view addSubview:viewController.view]; 
[self performSelector:@selector(secondViewController) withObject:nil afterDelay:40]; 
} 


-(void)secondViewController { 

SecondViewController *secondController = [[SecondViewController alloc] init]; 
secondController.view.frame = CGRectMake(0, 0, 320, 480); 
[self.view addSubview:secondController.view]; 
} 
1

的替代/除了由Aravindhanarviless詳述的方法是使用一個NSTimer該方法:

self.myTimer = [NSTimer scheduledTimerWithTimeInterval:40 target:self selector:@selector(showSecondViewController) userInfo:nil repeats:NO]; 
2

嘗試使視圖看不見,然後在40秒後迅速消失。

secondController.view.alpha = 0.0; 
[self.view addSubview:secondController.view]; 
[UIView animateWithDuration:0.5 
      delay:40 
      options:UIViewAnimationCurveEaseInOut 
      animations:^{ 
       secondController.view.alpha = 1.0; 
      } 
      completion:NULL 
];