4

I create a GLKViewController like this:

// Create a GLK View Controller to handle animation timings
_glkVC = [[GLKViewController alloc] initWithNibName:nil bundle:nil];
_glkVC.preferredFramesPerSecond = 60;
_glkVC.view = self.glkView;
_glkVC.delegate = self;
_glkVC.paused = YES;
NSLog(@"initial state: %@", _glkVC.paused ? @"paused" : @"running");

but it immediately starts calling the delegate update method and the output from the NSLog above is: initial state: running

I am managing my view updates with setNeedsDisplay but I want the GLKViewController to handle animations from time to time so I want to unpause it only when needed. Is there a way to start the controller in a paused state?

jhabbott
  • 18,461
  • 9
  • 58
  • 95

4 Answers4

2

have you tried pausing in the viewDidAppear method instead of the viewDidLoad method? It should look something like this:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];    
    // self.paused automatically set to NO in super's implementation
    self.paused = YES;
}

Boom, done! If this works then you save an "if" check thousands of times a minute just to pause on launch!

mogelbuster
  • 1,066
  • 9
  • 19
2

The viewDidAppear method works for me, but not optimally. A few frames of visible animation occur before the pause takes effect. Using viewWillAppear worked much better:

- (void) viewWillAppear: (BOOL) animated
{
  [ super viewDidAppear: animated ];
  self.paused = YES;
}
1

In lieu of any answers I'm using this work-around:

I set .preferredFramesPerSecond = 1 initially and then in the update method I check if(preferredFramesPerSecond == 1) and set .paused = YES (and also set my real desired value for preferredFramesPerSecond). I can then allow the rest of the update method to run once after initialisation, or return immediately if I don't want it to run yet.

I then trigger redraws manually as needed with setNeedsDisplay and unpause it when I need it to animate.

If anyone has a better solution please answer as usual.

jhabbott
  • 18,461
  • 9
  • 58
  • 95
1

Have you tried overriding resumeOnDidBecomeActive to return NO? This should keep the animation paused on any activation, including the first.

Steven McGrath
  • 1,717
  • 11
  • 20