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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:05:30+00:00 2026-05-30T03:05:30+00:00

I have my main view, and when a user taps a ‘Show’ button I

  • 0

I have my main view, and when a user taps a ‘Show’ button I want two things to happen:

  1. Fade in a black UIView with alpha 0.5 covering the entire parent
    view. I’ll refer to this as darkenBackground
  2. Slide the view of a second view controller
    (self.secondViewController.view) on top of darkenBackground

When a user is finished, they tap ‘Done’ and the following happens:

  1. darkenBackground fades out and is removed from the superview.
  2. self.secondViewController.view slides out of the screen in the
    bottom direction and is removed from the superview.

All animations working simultaneously.

So far, I’ve been able to achieve the first part (sort-of), transition-in. This works fine. But when the user taps ‘Done’ the transition-out does not work as required. The problems I’m faced with are:

  1. darkenBackground and self.secondViewController.view fade out and are removed, but
    self.secondViewController.view wasn’t supposed to fade out! I tried animating only the second view but it simply disappears without animation.
  2. When a user taps ‘Show’ for a second time
    (transition-in), the view from the previous transition
    appears before the animation takes place. It doesn’t look like it
    was removed from the superview previously.

Here is my code:

When a user taps ‘Show’:

- (IBAction)showSecondView {

    darkenBackground = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
    [darkenBackground setBackgroundColor:[UIColor blackColor]];
    [darkenBackground setAlpha:0.5];

    self.secondViewController.view.frame = CGRectMake(0, 0, 320, 460);
    self.secondViewController.view.backgroundColor = [UIColor clearColor];

    [CATransaction begin];

    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setType:kCATransitionFade];

    CATransition *animation2 = [CATransition animation];
    [animation2 setDuration:0.5];
    [animation2 setType:kCATransitionMoveIn];
    [animation2 setSubtype:kCATransitionFromTop];
    [animation2 setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [self.view addSubview:darkenBackground];
    [self.view addSubview:self.secondViewController.view];

    [[self.view layer] addAnimation:animation forKey:@"darkenBkgFadeIn"];
    [[self.secondViewController.view layer] addAnimation:animation2 forKey:@"ShowSecondView"];

    [CATransaction commit];
}

When a user taps ‘Done’ (A function defined in the secondViewController.m class where it refers to the main view controller variables through delegate):

- (IBAction)hideSecondView {

    [CATransaction begin];

    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setType:kCATransitionFade];

    CATransition *animation2 = [CATransition animation];
    [animation2 setDuration:0.5];
    [animation2 setType:kCATransitionPush];
    [animation2 setSubtype:kCATransitionFromBottom];
    [animation2 setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [self.myParentController.darkenBackground removeFromSuperview];
    [self.myParentController.secondViewController.view removeFromSuperview];

    [[self.myParentController.view layer] addAnimation:animation forKey:@"darkenBkgFadeOut"];
    [[self.myParentController.secondViewController.view layer] addAnimation:animation2 forKey:@"RemoveSecondView"];

    [CATransaction commit];
}

Ultimately I want to show the view in the same way that the TWTweetComposeViewController modal view appears, where the background darkens and the controller appears. I could just use a modal view controller, but the issue I have with that is that when presenting the view controller it only ‘appears’ and does not slide from the bottom (since I require a semi-transparent background, I cannot use the default context for the modal view).

Cannot figure this one out, would appreciate some guidance.

  • 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-30T03:05:31+00:00Added an answer on May 30, 2026 at 3:05 am

    I assume that self.myParentController.view used in -hideSecondView is the same view as self.view in -showSecondView. If this is the case, then you’re applying a transition to the whole view here:

    [[self.myParentController.view layer] addAnimation:animation forKey:@"darkenBkgFadeOut"];
    

    You added self.secondViewController.view as a subview of self.view in -showSecondView, so when you later perform a transition on self.myParentController.view, it’s going to apply the transition to all its subviews (i.e., self.secondViewController.view) as well.

    Instead of applying the transition to self.myParentController.view in -hideSecondView, apply it directly to darkenBackground:

    [[self.myParentController.darkenBackground layer] addAnimation:animation forKey:@"darkenBkgFadeOut"];
    

    If I recall correctly, you can apply CATransitions when layers are added/removed to/from a view. If not, then you’ll have to wrap darkenBackground in a separate container view and perform the transitions on that so it doesn’t include self.secondViewController.view when you do the fade out.

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

Sidebar

Related Questions

I have a view that sets its hidden when the user taps the main
i have a main view controller with two subview in it,one is note-view and
I have two backbone Views. One is the main view and the other is
I have a silverlight mvvm application that loads main view with 2 user controls
I want to detect when a user taps anywhere in a view in my
i have a text held in my main view and a button next to
I'm writing a Silverlight app using the MVVM pattern. I have a main view
I have an application composed of a main view and a secondary view which
I have an Android app with a ListActivity in the main view. The list
I have an iPhone app that hides the status bar. However, my main view

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.