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

  • Home
  • SEARCH
  • 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 8364893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:32:17+00:00 2026-06-09T12:32:17+00:00

I have a complex Quartz routine in drawRect for a custom UIView subclass. It

  • 0

I have a complex Quartz routine in drawRect for a custom UIView subclass. It can take a few seconds to draw. What I’d like is to show a UIActivityIndicator while it is drawing. But then the indicator must stop spinning (and get hidden) after the drawing is complete.

I tried to start the animation of the indicator and then use performSelector for a custom method that simply calls setNeedsDisplay – my thinking is that performSelector will wait until the next run loop, right? In which case, my indicator has time to start on the main thread. This seems to be working, but as soon as I add the code to the end of drawRect to stop the animation, the indicator doesn’t show up at all, as if this animation is ending before it’s had a chance to begin.

Any suggestions?

I call the drawing like this:

[self.spinner startAnimating];
[self performSelectorOnMainThread:@selector(redraw) withObject:nil waitUntilDone:YES];//tried both YES and NO here

-(void)redraw{
[self.customView setNeedsDisplay];

}

The drawRect: simply has this at the end:

 - (void)drawRect:(CGRect)rect{
  //bunch of drawing
  [self.nav stopSpinner]; // reference to a controller class
   }

In self.nav object is this:

 -(void)stopSpinner{
self.spinner.hidden=YES;
[self.spinner stopAnimating];
}

And the spinner object is initially created like this:

    self.spinner=[[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]autorelease];
    self.spinner.hidden=YES;
    [self.viewController.view addSubview:self.spinner];
  • 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-09T12:32:19+00:00Added an answer on June 9, 2026 at 12:32 pm

    Perform your drawing on a background thread. Not only will this allow you to throw up an activity indicator and have it animate as desired, but the drawing itself with be much much faster. In my tests, I’ve seen a speed increase of 10X in complex Quartz drawing on a background thread.

    And it’s not hard. In fact, it might be so fast you won’t need the activity indicator.

    Here’s the code, and you can simply use a regular UIImageView and then assign its image property to the rendered output from the other thread:

     dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    
      dispatch_async(queue, ^{
    
        UIGraphicsBeginImageContext(self.bounds.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        //perform some drawing into this context
    
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
    
        dispatch_sync(dispatch_get_main_queue(), ^{
            self.imageView.image=viewImage;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex action which can take a long time to run. If
I have some complex message to show inside of a flash message so instead
I have several complex data structures like Map< A, Set< B > > Set<
Suppose I have complex objects, like structs containing a huge amount of members -
I have two complex objects like Object1 and Object2 . They have around 5
I have complex logical expression that look like this: ((((!((cond1) || (cond2) || (cond3))
I have two CAShapeLayers insde the main layer of UIView. The CAShapeLayers have complex
When I use SOAP, can I have complex datatypes as returnvalues or parameters example:
I have complex data structure, like this: OrderedHash, keys are dates and values are
I have complex-type object of entity framework. I would like buid dynamically select and

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.