Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Photo Browser iPhone App View Controller Transitions Implementing Full Screen Transitions

Chris Hinton
Chris Hinton
Courses Plus Student 12,588 Points

Custom transition background

Hi guys,

I'm going through the Implementing Full Screen Transitions video and, as far as I can see, my code is the same as Sam's.

However, when I bring up my view with the custom transition, the background is totally transparent, not white as was specified in the DetailViewController's viewDidLoad method.

I'm using IOS SDK 7.1 and just wondered whether anyone else had come across this. If so, any thoughts on what I could be doing wrong?


1 Answer

Chris Hinton
Chris Hinton
Courses Plus Student 12,588 Points

OK, I got it working by moving where the view's background colour is set. Rather than setting the background in DetailViewController, I set it in the PresentDetailTransition's animateTransition method.

I'm not sure if that's the best way to do it, but it does work.

So my animateTransition method now reads:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    UIViewController *detail = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *containerView = [transitionContext containerView];

    CGRect frame = containerView.bounds;
    frame.origin.y += 20.0;
    frame.size.height -= 20.0;

    detail.view.alpha = 0.0;
    detail.view.frame = frame;
    detail.view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.95];  //Moved here from DetailViewController
    [containerView addSubview:detail.view];

    [UIView animateWithDuration:0.3 animations:^{
        detail.view.alpha = 1.0;
    } completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];

Thanks you so much! Works like a charm.

Unfortunately, this didn't work for me. I'm not seeing any alpha transparency. Newer version of Xcode?

Also, the status bar color appears for a second, then turns to white. I've tried to implement the status bar color for the "containerView" as well, but not sure how to do it because the example shown is for the rootViewController, which is a UIViewController and not a UIView.