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 8485245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:35:18+00:00 2026-06-10T20:35:18+00:00

Since I have to draw many points in a UIview, I’d like to display

  • 0

Since I have to draw many points in a UIview, I’d like to display an activity indicator view over the UIView.

I tried something like this, but it doesn’t work.

-(void) drawRect:(CGRect)rect
{
     [self.activityIndicatorView startAnimating];

     CGContextRef cr = UIGraphicsGetCurrentContext();
     // Lots of CG functions (take a few seconds)

     [self.activityIndicatorView startAnimating];
}

What can I do to show a spinning wheel while drawing?


Edit with a solution (thanks @dasblinkenlight):

Two UIImageViews, one to be used as a placeholder (where the UIActivityIndicatorView runs), and another one that draws the CG content, named Renderer.

As read here the Renderer class writes a UIImage. Placing the drawrect call in another queue (background) when it finishes the placeholder can use the image to be displayed.

That’s the code:

dispatch_queue_t myQueue = dispatch_queue_create(“MyQueue”, 0);

dispatch_async(myQueue, ^{
    [self.renderer drawRect:self.placeholder.bounds];

    dispatch_async(dispatch_get_main_queue(), ^{
        [self.placeholder setImage:[self.renderer renderedImage]];
    });
});

I stil can’t understand why I have to call directly the drawRect function, instead of the setNeedDisplay. Is maybe because it is running in background?

  • 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-06-10T20:35:20+00:00Added an answer on June 10, 2026 at 8:35 pm

    You cannot do that: while your drawRect is executing, no other updates to the screen are possible; the spinning gear will not get a chance to be drawn or updated.

    If your drawRect takes a few seconds, you should reconsider your strategy: perhaps you could isolate the drawing-intensive code in a function that draws to an in-memory bitmap, show a UIImageView with a placeholder image in place that was to be painted by your drawRect code, do the rendering in a background thread, and replace the image of the UIImageView with what your code has painted.

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

Sidebar

Related Questions

I have no code to really display here, since I have not been able
I have a custom UIView which is composed of many images, their positions are
I have a requirement where I have to draw a view's shadow beyond the
In my app, I have to draw some images on a view, in real-time,
Since I have no errors I don't know if this is the right place
Its been a while since i have coded c++ and i have forgot an
It's been a while since I have used VBA on Excel. I want to
It's been a while since I have worked with ASP.Net and C#. I am
I wrote the following loop since I have to repeat the same/similar code 25
I am not sure my title is correct or not since I have no

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.