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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:06:27+00:00 2026-06-04T19:06:27+00:00

Say I have a subclass of UIView which I will call AnimatableView , where

  • 0

Say I have a subclass of UIView which I will call AnimatableView, where my implementation of layoutSubviews lays out some internal content.

AnimatableView also has the method commenceAnimationLoop which looks something like this:

- (void) commenceAnimationLoop {

    NSOperation *animationLoop = [[AnimationLoopOperation alloc]init];
    [queue addOperation:animationLoop]; //queue is a NSOperationQueue iVar of AnimatableView
    [animationLoop release];
}

The AnimationLoopOperation is a subclass of NSOperation whose main method will start an infinite animation which only exits once the isCancelled property becomes YES.

The problem I am having is in my ViewController where I setup and animate an instance of AnimatableView like so:

- (void) viewDidLoad {
    AnimatableView *animatableView = [AnimatableView alloc]initWithFrame:someFrame];

    [self.view addSubview: animatableView];
    [animatableView commenceAnimationLoop];

    [animatableView release];
}

The problem is that the NSOperation created in the commenceAnimationLoop executes before my instance of AnimatableView has had chance to call layoutSubviews (meaning that it’s content has not yet been generated and laid out).

I am making an educated guess that the layoutSubviews method is called later (when the ViewController is ready to render its view hierarchy?), but that the commenceAnimationLoop method spawns a thread that immediately executes in the background.

To summarise – what would be the best way to make my animationLoop operation wait for the view to layout before commencing?

To provide some high level context for what I am trying to achieve – I am using NSOperation to start a continuous animation. The idea being that I can provide an endAnimation method which would likely call cancelAllOperations on my queue. All this is done in the hopes I can provide a way of starting and then interrupting an infinite animation with the two methods commenceAnimationLoop and endAnimation. Perhaps I am barking up the wrong tree going down the route of multi-threading?

  • 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-04T19:06:29+00:00Added an answer on June 4, 2026 at 7:06 pm

    If you need layoutSubviews to run before your operation then you should’t start the operation queue before it that. You can prevent an operation queue from starting additional operations using [myOperationQueue setSuspended:YES];.

    Since it will only prevent the queue from starting new operations you should suspend the queue before you add your operations to it.

    After you view has loaded and layoutSubviews has run you can resume the operation queue again using [myOperationQueue setSuspended:NO];. One place to do this could be in viewDidAppear.

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

Sidebar

Related Questions

If I have some instance of a class, say a UIView or subclass of
Say I have a class Foo, a class A and some subclass B of
Let's say we have this part of code for a UIView subclass: self.myImage =
Say I have an abstract class Base, of which another abstract class Subclass extends.
I have a custom NSManagedObject subclass, say, Person . I also have a UIView
Lets say I have a class named Dog which is a subclass of Animal
Say I have superclass which listens to a notification: @implementation SuperClass - (void)viewWillAppear:(BOOL)animated {
Say we have an out-proc COM server and a client. The client calls a
I currently have a simple iPhone app that loads a custom subclass of UIView.
Here's a hypothetical question: Say I subclass a UIView that draws a triangle 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.