0

このような遅延で複数のView Controllerを次々にロードする

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

このようにコンテナビューにすべてのviewcontrollersをロードしても問題ないか、ここで何か間違ったことをしています。

このための助けに感謝します。

ありがとう。

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 に答える