Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 778327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:44:48+00:00 2026-05-14T19:44:48+00:00

Does anyone know or have good links that explain what iPhone’s event loop does

  • 0

Does anyone know or have good links that explain what iPhone’s event loop does under the hood?

We are using a custom event loop in our OpenGL-based iPhone game framework. It calls our game rendering system, calls presentRenderbuffer and pumps events using CFRunLoopRunInMode. See the code below for details.

It works well when we are not using UIKit controls (as a proof, try Facetap, our first released game).

However, when using UIKit controls, everything almost works, but not quite. Specifically, scrolling of UIKit controls doesn’t work properly.

For example, let’s consider following scenario.

  • We show UIImagePickerController on top of our own view.
  • UIImagePickerController covers our custom view
  • We also pause our own rendering, but keep on using the custom event loop.

As said, everything works, except scrolling.

  • Picking photos works.
  • Drilling down to photo albums works and transition animations are smooth.
  • When trying to scroll photo album view, the view follows your finger.

Problem: when scrolling, scrolling stops immediately after you lift your finger. Normally, it continues smoothly based on the speed of your movement, but not when we are using the custom event loop. It seems that iPhone’s event loop is doing some magic related to UIKit scrolling that we haven’t implemented ourselves.

Now, we can get UIKit controls to work just fine and dandy together with our own system by using Apple’s event loop and calling our own rendering via NSTimer callbacks. However, I’d still like to understand, what is possibly happening inside iPhone’s event loop that is not implemented in our custom event loop.

- (void)customEventLoop { OBJC_METHOD;
  float excess = 0.0f;
  while(isRunning) {
    animationInterval = 1.0f / openGLapp->ticks_per_second();

    // Calculate the target time to be used in this run of loop
    float wait = max(0.0, animationInterval - excess); 
    Systemtime target = Systemtime::now().after_seconds(wait);

    Scope("event loop");

    NSAutoreleasePool* pool = [[ NSAutoreleasePool alloc] init];

    // Call our own render system and present render buffer 
    [self drawView];
    // Pump system events
    [self handleSystemEvents:target];

    [pool release];

    excess = target.seconds_to_now();
  }
}

- (void)drawView { OBJC_METHOD;

  // call our own custom rendering
  bool bind = openGLapp->app_render();

  // bind the buffer to be THE renderbuffer and present its contents
  if (bind) {
    opengl::bind_renderbuffer(renderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
  }
}

- (void) handleSystemEvents:(Systemtime)target { OBJC_METHOD;
  SInt32 reason = 0;
  double time_left = target.seconds_since_now();
  if (time_left <= 0.0) {
    while((reason = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE)) == kCFRunLoopRunHandledSource) {}
  } else {
    float dt = time_left;
    while((reason = CFRunLoopRunInMode(kCFRunLoopDefaultMode, dt, FALSE)) == kCFRunLoopRunHandledSource) {
      double time_left = target.seconds_since_now();
      if (time_left <= 0.0) break;
      dt = (float) time_left;
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:44:48+00:00Added an answer on May 14, 2026 at 7:44 pm

    If you NSLog [[NSRunLoop currentRunLoop] currentMode] from [UIScrollView setContentOffset:] when [UIScrollView isDecelerating] is true you will see UITrackingRunLoopMode.

    In general, the system will use modes besides kCFRunLoopDefaultMode on the main UI thread run loop, only some of which are documented. The only way to get full system behavior is to cooperate with the system run loop on the main thread.

    You could try using an NSTimer and letting the system call you instead of calling CFRunLoopRunInMode yourself. An NSTimer is free to run over time, and when no other UI is shown the system run loop would not be doing anything besides calling the timer.

    The alternative would be to return from your customEventLoop function while system controls are being displayed, and call it again when resuming your custom UI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know there have any other way that (by not using json_encode and
Does anyone know of a good way to have a user enter an amount
Does anyone know do there have any way that I can encrypt the array
Does anyone know, or better yet have an example, of a WCF service that
Does anyone have a good link to know what technologies and platform is being
Does anyone know of a good module (or technique) that can be used to
Does anyone have or know of a good template / plan for doing automated
Does anyone know of a good software development framework or similar that has the
Does anyone know of a tool or have a good solution for QA to
Does anyone know if there have been any changes in Azure publish to allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.