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

The Archive Base Latest Questions

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

I am trying to put together a simple container view controller that will allow

  • 0

I am trying to put together a simple container view controller that will allow me to present child view controllers from any direction (from the right like the standard navigation controller, put also from the top, bottom and left.

Developping for iOS 5, I use the parent/child view controller relationships and use a transitionFromViewController with a custom animation block to slide in the views.

All messages (viewWillAppear, etc.) are all passed on correctly to the child view controllers, but the problem is that for example viewWillAppear seems to be called from inside an animation loop (i.e. when I set animatable properties -like backgroundColor, or frame of subviews- of the view of the child view controller, they are actually animated). I do not want this behaviour, as I would like to use the viewWillAppear methods to perform initialization before showing the view controllers. I do not want this code to be animated.

Here is a simplified version of my code:

@implementation ContainerViewController
@synthesize currentViewController;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];

    self.currentViewController = [[SimpleViewController alloc] init];
    [self addChildViewController:self.currentViewController];
    self.currentViewController.view.frame = self.view.bounds;
    [self.view addSubview:self.currentViewController.view];
}

- (void) slideViewController {
    UIViewController* previousViewController = self.currentViewController;

    UIViewController* viewController = [[SimpleViewController alloc] init];
    viewController.view.frame = CGRectOffset(self.view.bounds, self.view.bounds.size.width, 0);
    [self addChildViewController:viewController];
    [previousViewController willMoveToParentViewController:nil];

    [self transitionFromViewController:previousViewController toViewController:viewController duration:1.0 options:UIViewAnimationOptionTransitionNone animations:^{
        viewController.view.frame = self.view.bounds;
    } completion:^(BOOL finished) {
        [previousViewController removeFromParentViewController];
        [viewController didMoveToParentViewController:self];
    }];

    self.currentViewController = viewController;
}

- (void) loop {
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self slideViewController];
        [self loop];
    });
}

- (void)viewDidAppear:(BOOL)animated {
    [self loop];
}

@end


@implementation SimpleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)viewWillAppear:(BOOL)animated {
    CGFloat red = (arc4random()%256)/255.0;
    CGFloat green = (arc4random()%256)/255.0;
    CGFloat blue = (arc4random()%256)/255.0;
    self.view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1];
}

@end

If you try to run this code, you will see a new view controller slide from the right. The problem is that the backgroundColor of the view of that view controller gets animated from white to a random color (see viewWillAppear method of SimpleViewController). I would like that the backgroundColor of the view would be set immediately without being animated.

  • 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-10T08:18:36+00:00Added an answer on June 10, 2026 at 8:18 am

    I found a workaround, by disabling the animation of properties in the viewWillAppear method (see Disabling implicit animations in -[CALayer setNeedsDisplayInRect:] thread for details)

    The code can be wrapped inside a CATransaction to commit changes without animation.

    - (void)viewWillAppear:(BOOL)animated {
        [CATransaction begin];
        [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
    
        CGFloat red = (arc4random()%256)/255.0;
        CGFloat green = (arc4random()%256)/255.0;
        CGFloat blue = (arc4random()%256)/255.0;
    
        self.view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1];
    
        [CATransaction commit];
    }
    

    However I wonder if anybody else has run into this problem and if there is a better method to solve it?

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

Sidebar

Related Questions

I'm trying to put together a simple RSS widget (for my wordpress blog) that
I trying to put together an Android app that will take a picture and
Right now I'm trying to put together something really simple, learn from it, and
I am currently trying to put together a simple Illustrator plugin, and coming from
Okay, so here's the deal: I'm trying to put together a script that will
I'm trying to put together a simple table that shows my model's data. I
I'm trying to put together a layout using Bootstrap that resembles your typical OS
I'm trying to put together a fun 'contest' of sorts. Developers will write a
I am trying to put together a simple POC for a n-layer application using
I have been trying to put together something that allows me to extract points

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.