How to create a GLKViewController that starts in pause state?

I create a GLKViewController as follows:

 // 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 immediately starts calling the delegate update method, and the output from NSLog higher: initial state: running

I manage my view updates with setNeedsDisplay , but I want the GLKViewController process animations from time to time, so I want it to be disabled only when necessary. Is there a way to start the controller in pause state?

+4
source share
4 answers

Instead of the answers, I use this work:

I first set .preferredFramesPerSecond = 1 , and then in the update method, I checked if(preferredFramesPerSecond == 1) and set .paused = YES (and also set the true value for preferredFramesPerSecond ). I then allow the rest of the update method to run once after initialization, or return immediately if I do not want it to run yet.

Then I start redrawing manually as needed with setNeedsDisplay and pause it when I need to animate it.

If someone has a better solution, answer as usual.

+1
source

Have you tried to pause 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 implementation self.paused = YES; } 

Boom done! If this works, then you save the "if" check thousands of times per minute to pause the launch!

+2
source

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

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

Have you tried to override resumeOnDidBecomeActive to return NO ? This should cause the animation to pause on any activation, including the first.

+1
source

Source: https://habr.com/ru/post/1441412/


All Articles