Question

Hi maybe this is a duplicated question and I just don't know the keyword to describe my question, if this is the case please point out.

I'm currently implementing a transition between two view, as the second view shows, it should looked like it's zoomed into the screen from outside, kind of fall on the screen. My idea is to zoom the second view 9 * original size and place the origin to -original_width, -original_height, and set alpha to 0. At the end I set alpha to 1 and show the original size.

so the following code is not working, the subviews are not resized. Could anyone tell me what I miss here or better show me some API which do the task?

[toVC.view setFrame:CGRectMake(0-fromVC.view.frame.size.width, 0-screenRect.size.height, fromVC.view.frame.size.width*3, fromVC.view.frame.size.height*3)];
    for (UIView* view in toVC.view.subviews) {
        CGRect frame = view.frame;
        [view setFrame:CGRectMake(frame.origin.x*3, frame.origin.y*3, frame.size.width*3, frame.size.height*3)];
    }
    [toVC.view layoutIfNeeded];
    [toVC.view setAlpha:0.1];
    [UIView animateWithDuration:duration*5
                     animations:^{
                         [toVC.view setAlpha:1.0];
                         [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];
                         for (UIView* view in toVC.view.subviews) {
                             CGRect frame = view.frame;
                             [view setFrame:CGRectMake(frame.origin.x/3, frame.origin.y/3, frame.size.width/3, frame.size.height/3)];
                         }
                     }
                     completion:^(BOOL finished) {
                         [transitionContext completeTransition:YES];
                     }];
Was it helpful?

Solution

You could just set the view transform prior and after the transition:

CGAffineTransform scaleTransform = CGAffineTransformIdentity;
scaleTransform = CGAffineTransformScale(rotationTransform, 9., 9.);
view.transform = scaleTransform;
view.alpha = 0;
[UIView animateWithDuration:duration*5
                     animations:^{
                         view.transform = CGAffineTransformIdentity;
                         view.alpha = 1.;
                         }
                     }
                     completion:^(BOOL finished) {
                     }];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top