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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:35:47+00:00 2026-05-26T06:35:47+00:00

Currently I am having a issue switching views using Core Animation. I want to

  • 0

Currently I am having a issue switching views using Core Animation. I want to fade through black switching to my next view.
Right now it does not do anything besides lose touch events from my original view.
What am I doing wrong in the code below?

Edit1 Code:

    - (void)changeView1ToView2 {
    CABasicAnimation *fadeout= [CABasicAnimation animationWithKeyPath:@"opacity"];
    [fadeout setDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
    [fadeout setToValue:[NSNumber numberWithFloat:0]];
    [fadeout setDuration:0.5];
    [[self.view layer] addAnimation:fadeout forKey:@"alpha"];
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
    [self.view addSubview:self.view2.view];
    self.view2.view.frame = [UIScreen mainScreen].bounds;
    [self.view2.view setAlpha:0];
    CABasicAnimation *fadein = [CABasicAnimation animationWithKeyPath:@"opacity"];
    [fadein setToValue:[NSNumber numberWithFloat:1.0]];
    [fadein setDuration:0.5];
    [[self.view2.view layer] addAnimation:fadein forKey:@"alpha"];
}

Ok I added self, look at my new code above. view2 is a UIViewController, thats why I am doing .view after it. The app is only going to be available on iOS 5 or up so thats not a problem. But what I am trying to achieve is switching views using Core Animation, and have each UIViewController manage their own views. I am just switching views using Core Animation instead of usual means.

  • 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-26T06:35:48+00:00Added an answer on May 26, 2026 at 6:35 am

    If you’re looking to have only one root view on screen at one time (and by the looks of that call to [UIScreen mainScreen].bounds, you are), then I’d suggest swapping the views at the UIWindow level. Without animations, this would look something like this:

    // Assuming UIViewControllers called view1 and view2 as members of some
    // (non-UIViewController) controller class (self, in this case)
    //and that view1.view is in the application's window's subviews collection
    [self.view1.view removeFromSuperview];
    [[UIApplication sharedApplication].delegate.window addSubview:self.view2.view];
    

    In terms of not seeing the views actually swap, you need to ensure that your animation preserves the changes you make during the animation. Specifically, you need to set the following:

    myAnimation.fillMode = kCAFillModeForwards;
    myAnimation.removedOnCompletion = NO;
    

    Your methods can then be adjusted to take all this into account. For example, your animationDidStop:finished: method might look like this:

    - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
    {
        [self.view1.view removeFromSuperview];
    
        [self.view2.view setAlpha:0];
        [[UIApplication sharedApplication].delegate.window addSubview:self.view2.view];
    
        CABasicAnimation *fadein = [CABasicAnimation animationWithKeyPath:@"opacity"];
        [fadein setToValue:[NSNumber numberWithFloat:1.0]];
        [fadein setDuration:0.5];
        fadein.fillMode = kCAFillModeForwards;
        fadein.removedOnCompletion = NO;
        [[self.view2.view layer] addAnimation:fadein forKey:@"alpha"];
    }
    

    You may need to muck around with it a bit to ensure that everything is firing correctly.

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

Sidebar

Related Questions

I'm currently having the following issue in my project: I'm using Core Data to
I'm currently using this jQuery validate plugin and having an issue in IE where
I'm currently having an issue with using custom ListView adapters with the Holo.Light theme.
I'm currently having an issue with a trigger I'm writing. I want to do
I currently am having a issue with my main XIB. I am using iOS
I am currently having an issue with BackgroundWorker running on Windows Server 2003. I
I'm currently having an issue wrapping my brain around the notion of converting my
Hi All I am currently having an issue calling a WCF service from a
I'm currently having a major issue with a python script. The script runs arbitrary
Hopefully someone can shed a little light on an issue that I'm currently having

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.