Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Chris Hinton
PLUS
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?

Thanks.

1 Answer

Chris Hinton
PLUS
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.